Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add basic structure for models, controllers,
- Loading branch information
1 parent
c4a0476
commit c258ef5
Showing
1 changed file
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// app/Models/Example.php | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Example extends Model | ||
{ | ||
protected $fillable = ['name', 'description']; | ||
} | ||
|
||
// app/Http/Controllers/ExampleController.php | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Example; | ||
use Illuminate\Http\Request; | ||
|
||
class ExampleController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$examples = Example::all(); | ||
return response()->json($examples); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$example = Example::create($request->all()); | ||
return response()->json($example, 201); | ||
} | ||
} | ||
|
||
// app/Policies/ExamplePolicy.php | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\User; | ||
use App\Models\Example; | ||
|
||
class ExamplePolicy | ||
{ | ||
public function viewAny(User $user) | ||
{ | ||
// Define logic to determine if the user can view any examples | ||
return true; | ||
} | ||
|
||
public function view(User $user, Example $example) | ||
{ | ||
// Define logic to determine if the user can view a specific example | ||
return true; | ||
} | ||
|
||
public function create(User $user) | ||
{ | ||
// Define logic to determine if the user can create an example | ||
return true; | ||
} | ||
|
||
public function update(User $user, Example $example) | ||
{ | ||
// Define logic to determine if the user can update a specific example | ||
return true; | ||
} | ||
|
||
public function delete(User $user, Example $example) | ||
{ | ||
// Define logic to determine if the user can delete a specific example | ||
return true; | ||
} | ||
} |