Код: Выделить всё
//Leases
Route::resource('properties.leases', LeaseController::class)
->only(['show'])
->shallow();
//Invoices
Route::resource('leases.invoices', InvoiceController::class)
->only(['index', 'show'])
->shallow();
Код: Выделить всё
| GET|HEAD | leases/{lease} | App\Http\Controllers\LeaseController@show |
| GET|HEAD | leases/{lease}/invoices | App\Http\Controllers\InvoiceController@index |
| GET|HEAD | invoices/{invoice} | App\Http\Controllers\InvoiceController@show |
Код: Выделить всё
Properties hasMany Leases.
Leases hasMany Invoices.
- принадлежат к той же команде, что " «Аренда» и «Счета-фактуры» также принадлежат.
- В данный момент вошел в эту команду.
Код: Выделить всё
protected $policies = [
Lease::class => LeasePolicy::class,
Invoice::class => InvoicePolicy::class,
];
Код: Выделить всё
public function __construct()
{
$this->authorizeResource(Lease::class, 'lease');
}
Код: Выделить всё
public function view(User $user, Lease $lease)
{
//Does the current user belong to the team that the lease is associated with
//and is the user's current team the same one?
$team = $lease->property->team;
return $user->belongsToTeam($team) && $user->isCurrentTeam($team);
}
Код: Выделить всё
public function __construct()
{
$this->authorizeResource(Invoice::class, 'invoice');
}
Код: Выделить всё
/**
* Path: leases/{lease}/{$invoice}
*/
public function viewAny(User $user)
{
//When users go to this path I can only access $user here.
//How to check if the user can even access the $lease.
}
/**
* Path: invoices/{$invoice}
*/
public function view(User $user, Invoice $invoice)
{
//Does the current user belong to the team that the lease is associated with
//and is the user's current team the same one?
$team = $invoice->lease->property->team;
return $user->belongsToTeam($team) && $user->isCurrentTeam($team);
}
Код: Выделить всё
//Files
Route::resource('leases.files', FileController::class)
->only(['index'])
->shallow();
Подробнее здесь: https://stackoverflow.com/questions/710 ... ressources
Мобильная версия