Skip to content

Commit

Permalink
curso factory and policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lobz committed Jul 26, 2024
1 parent f143e21 commit 315383f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/Policies/CursoPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Policies;

use App\Models\Curso;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class CursoPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return mixed
*/
public function create(User $user)
{
return $user->isAdmin();
}

/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\Curso $curso
* @return mixed
*/
public function edit(User $user, Curso $curso)
{
return $user->isAdmin();
}

/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Curso $curso
* @return mixed
*/
public function delete(User $user, Curso $curso)
{
return $user->isAdmin();
}
}
29 changes: 29 additions & 0 deletions database/factories/CursoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use App\Models\Curso;
use Illuminate\Database\Eloquent\Factories\Factory;

class CursoFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Curso::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => substr($this->faker->sentence(2), 0, -1),
'description' => $this->faker->paragraph,
];
}
}

0 comments on commit 315383f

Please sign in to comment.