-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adicionadno modelos ao medicos e profissionais
- Loading branch information
1 parent
1f65d8c
commit b997955
Showing
13 changed files
with
305 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Model\Usuario; | ||
use App\Model\Modelo; | ||
|
||
class ModeloController extends Controller | ||
{ | ||
public function lista() { | ||
$usuario = Usuario::find(auth()->user()->id); | ||
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico; | ||
|
||
$select = []; | ||
|
||
foreach ($medico->modelos as $mol) { | ||
$select[$mol->id] = $mol->titulo; | ||
} | ||
|
||
$modelo = new Modelo; | ||
|
||
if(isset($_GET['modelo'])) { | ||
$m = Modelo::find($_GET['modelo']); | ||
|
||
if($m) { | ||
if($m->medico_id == $usuario->id) { | ||
$modelo = $m; | ||
} | ||
} | ||
} | ||
|
||
return view('modelos.lista', compact('medico', 'select', 'modelo')); | ||
} | ||
|
||
public function novo(Request $r) { | ||
$usuario = Usuario::find(auth()->user()->id); | ||
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico; | ||
|
||
if($r->tipo == 'novo') { | ||
Modelo::create($r->all() + [ 'medico_id' => $medico->usuario_id ]); | ||
|
||
return redirect('modelos')->withMsg('Modelo foi criado!'); | ||
} | ||
|
||
$m = Modelo::find($r->modelo); | ||
$m->fill($r->all()); | ||
$m->save(); | ||
|
||
return redirect('modelos')->withMsg('Modelo foi editado!'); | ||
|
||
} | ||
|
||
public function manipular(Request $r) { | ||
$usuario = Usuario::find(auth()->user()->id); | ||
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico; | ||
|
||
if($r->acao == 'Apagar') { | ||
Modelo::destroy($r->modelo); | ||
return redirect('modelos')->withMsg('Modelo foi apagado!'); | ||
} | ||
|
||
return redirect('modelos?modelo='.$r->modelo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Model; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Modelo extends Model | ||
{ | ||
public $timestamps = false; | ||
|
||
protected $fillable = [ | ||
'titulo', | ||
'conteudo', | ||
'medico_id' | ||
]; | ||
|
||
public function usuario() | ||
{ | ||
return $this->belongsTo(Usuario::class, 'medico_id', 'usuario_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
ALTER TABLE `consultas` | ||
CHANGE COLUMN `status` `status` VARCHAR(250) NOT NULL COLLATE 'utf8mb4_unicode_ci' AFTER `obs`; | ||
|
||
|
||
|
||
CREATE TABLE IF NOT EXISTS `modelos` ( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`titulo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, | ||
`conteudo` text COLLATE utf8mb4_unicode_ci NOT NULL, | ||
`medico_id` int(10) unsigned NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `modelos_medico_id_foreign` (`medico_id`), | ||
CONSTRAINT `modelos_medico_id_foreign` FOREIGN KEY (`medico_id`) REFERENCES `usuarios` (`id`) ON DELETE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
38 changes: 38 additions & 0 deletions
38
src/database/migrations/2017_09_30_220718_create_modelos_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateModelosTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('modelos', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('titulo'); | ||
$table->text('conteudo'); | ||
$table->integer('medico_id')->unsigned(); | ||
|
||
$table->foreign('medico_id') | ||
->references('id') | ||
->on('usuarios') | ||
->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('modelos'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
@extends('layouts.app') | ||
|
||
@section('titulo', 'Seus modelos') | ||
|
||
@section('lateral') | ||
@endsection | ||
|
||
@section('conteudo') | ||
<p style="text-align:center"> | ||
@if(session('msg')) | ||
<span class="texto-verde"> | ||
{{ session('msg') }} | ||
</span> | ||
@endif | ||
|
||
@if(session('erro')) | ||
<span class="texto-vermelho"> | ||
{{ session('erro') }} | ||
</span> | ||
@endif | ||
</p> | ||
|
||
{{ Form::open(['url' => 'modelos/manipular', 'method' => 'post']) }} | ||
<section> | ||
<div> | ||
{{ Form::label('modelo', 'Modelo') }} | ||
{{ Form::select('modelo', $select, $modelo->id, | ||
['required' => ''] | ||
) }} | ||
|
||
<input type="submit" name="acao" value="Apagar" class="btn vermelho" style='flex-grow: 1; margin-left: 3px' onclick="return confirm('Deseja realmente apagar?')"> | ||
<input type="submit" name="acao" value="Editar" class="btn amarelo" style='flex-grow: 1; margin-left: 3px'> | ||
|
||
</div> | ||
</section> | ||
{{ Form::close() }} | ||
|
||
{{ Form::open(['url' => 'modelos', 'method' => 'post']) }} | ||
<header> | ||
@if($modelo->id != null) | ||
Editar modelo | ||
@else | ||
Novo modelo | ||
@endif | ||
</header> | ||
|
||
<section> | ||
|
||
@if($modelo->id != null) | ||
<input type="hidden" name="tipo" value="editar"> | ||
<input type="hidden" name="modelo" value="{{ $modelo->id }}"> | ||
@else | ||
<input type="hidden" name="tipo" value="novo"> | ||
@endif | ||
|
||
<div> | ||
{{ Form::label('titulo', 'Título (Apelido)') }} | ||
{{ Form::text('titulo', $modelo->titulo, ['required' => '']) }} | ||
</div> | ||
|
||
<div> | ||
{{ Form::label('conteudo', 'Conteúdo') }} | ||
{!! Form::textarea('conteudo', $modelo->conteudo, ['required' => '', 'placeholder' => 'Digite seu modelo'] ) !!} | ||
</div> | ||
</section> | ||
|
||
<footer> | ||
<section> | ||
<input type="submit" value="Salvar esse modelo" class="btn verde"> | ||
</section> | ||
|
||
<span class="texto-vermelho">{{ $errors->first() }}</span> | ||
</footer> | ||
{{ Form::close() }} | ||
|
||
<script> | ||
CKEDITOR.config.width = '100%'; | ||
CKEDITOR.replace( 'conteudo' ); | ||
</script> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.