From 545187d18fdc3fda284d9d6b26adb77a83bd6bfe Mon Sep 17 00:00:00 2001
From: Guilherme Silva <guilherme.dna06@gmail.com>
Date: Sun, 30 Jan 2022 17:42:57 -0300
Subject: [PATCH] =?UTF-8?q?Adicionado=20notifica=C3=A7=C3=A3o=20ao=20siste?=
 =?UTF-8?q?ma?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Controllers/NotificacaoController.php     | 99 +++++++++++++++++++
 app/Notificacao.php                           | 29 ++++++
 ...01_24_222743_create_notificacaos_table.php | 42 ++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 app/Http/Controllers/NotificacaoController.php
 create mode 100644 app/Notificacao.php
 create mode 100644 database/migrations/2022_01_24_222743_create_notificacaos_table.php

diff --git a/app/Http/Controllers/NotificacaoController.php b/app/Http/Controllers/NotificacaoController.php
new file mode 100644
index 0000000..768ee26
--- /dev/null
+++ b/app/Http/Controllers/NotificacaoController.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Notificacao;
+use Illuminate\Http\Request;
+
+class NotificacaoController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Notificacao  $notificacao
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Notificacao $notificacao)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Notificacao  $notificacao
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Notificacao $notificacao)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Notificacao  $notificacao
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Notificacao $notificacao)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Notificacao  $notificacao
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Notificacao $notificacao)
+    {
+        //
+    }
+
+    public function listar()
+    {
+        $notificacoes = Notificacao::all()->sortBy('created_at');
+        return view('notificacao.listar',['notificacoes'=>$notificacoes]);
+    }
+
+    public function listarTrab()
+    {
+        $destinatarios =  Notificacao::where('destinatario_id',Auth()->user()->id)->get();
+        $remetentes =  Notificacao::where('remetente_id',Auth()->user()->id)->get();
+        $notificacoes = $destinatarios->merge($remetentes);
+        return view('notificacao.listar',['notificacoes'=>$notificacoes]);
+    }
+}
diff --git a/app/Notificacao.php b/app/Notificacao.php
new file mode 100644
index 0000000..cd6a717
--- /dev/null
+++ b/app/Notificacao.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Notificacao extends Model
+{
+    /**
+     * The attributes that are mass assignable.
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'lido', 'tipo', 'destinatario_id', 'remetente_id', 'perfil_id', 'trabalho_id',
+    ];
+
+    public function destinatario(){
+        return $this->belongsTo(User::class,'destinatario_id','id');
+    }
+
+    public function remetente(){
+        return $this->belongsTo(User::class,'remetente_id','id');
+    }
+
+    public function trabalho(){
+        return $this->belongsTo(Trabalho::class,'trabalho_id','id');
+    }
+}
diff --git a/database/migrations/2022_01_24_222743_create_notificacaos_table.php b/database/migrations/2022_01_24_222743_create_notificacaos_table.php
new file mode 100644
index 0000000..6f542b2
--- /dev/null
+++ b/database/migrations/2022_01_24_222743_create_notificacaos_table.php
@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateNotificacaosTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('notificacaos', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('remetente_id');
+            $table->integer('destinatario_id');
+            $table->integer('trabalho_id');
+            $table->integer('perfil_id')->nullable();
+            $table->boolean('lido');
+            $table->integer('tipo');  //1 para pediu acesso, 2 para recebeu acesso, 3 para objetivo, 4 atividade, 5 sugestao
+
+            $table->foreign('remetente_id')->references('id')->on('users');
+            $table->foreign('trabalho_id')->references('id')->on('trabalhos');
+            $table->foreign('destinatario_id')->references('id')->on('users');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('notificacaos');
+    }
+}
-- 
GitLab