Skip to content

Commit

Permalink
criação de api restful para conceitos
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolinkk committed Jun 10, 2022
1 parent d0891f2 commit 0df463f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/Http/Controllers/ConceitoControllerApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Conceito;

class ConceitoControllerApi extends Controller
{

public function index()
{
return Conceito::all();
}


public function store(Request $request)
{
Conceito::create($request->all());
}


public function show($id)
{
return Conceito::find($id);
}

public function update(Request $request, $id)
{
$conceito = Conceito::find($id);
$conceito->update($request->all());
}

public function destroy($id)
{
$conceito = Conceito::find($id);
$conceito->delete();
}
}
2 changes: 2 additions & 0 deletions app/Models/Conceito.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Conceito extends Model
{
use HasFactory;

protected $fillable = ['nome','descricao','user_id'];

public function usuario()
{
return $this->belongsTo(User::class);
Expand Down
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ConceitoControllerApi;

/*
|--------------------------------------------------------------------------
Expand All @@ -17,3 +18,5 @@
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});

Route::resource('conceito',ConceitoControllerApi::class);

0 comments on commit 0df463f

Please sign in to comment.