Traits

HasAttachment

use Bnb\Laravel\Attachments\HasAttachment;
Quickly attach files to your models, retrievable by key, group name or using the Eloquent relationship. Read full documentation on https://github.com/bnbwebexpertise/laravel-attachments

HasTranslations

use Spatie\Translatable\HasTranslations;
A trait to make Eloquent models translatable. Read full documentation on https://github.com/spatie/laravel-translatable

Taggable

use Conner\Tagging\Taggable;
Tag support for Laravel Eloquent models. Read full documentation on https://github.com/rtconner/laravel-tagging

HasSef

use TaffoVelikoff\LaravelSef\Traits\HasSef;
Search engine friendly URL for Eloquent models. Read full documentation on https://packagist.org/packages/taffovelikoff/laravel-sef

HasAccessRole

use TaffoVelikoff\HotCoffee\Traits\HasAccessRole;
A trait that allows you to assign access roles to Eloquent models. You can assign what user roles have the privilege view a model. Here is an example on how to assign roles and then authorize the user.
1
namespace App\Http\Controllers\Admin;
2
3
use App\InfoPage;
4
use App\Http\Controllers\Controller;
5
6
class InfoPageController extends Controller
7
{
8
/**
9
* Store a page
10
*/
11
12
public function store() {
13
// Create a product
14
$info = InfoPage::create(request()->all());
15
16
// Attach access roles
17
$info->access_roles()->attach(request()->roles);
18
}
19
}
Copied!
1
namespace App\Http\Controllers\Front;
2
3
use App\InfoPage;
4
use App\Http\Controllers\Controller;
5
6
class InfoPageController extends Controller
7
{
8
9
/**
10
* View a page
11
*/
12
13
public function index($id) {
14
15
// Find page
16
$page = InfoPage::findOrFail($id);
17
18
// Authorize users
19
$page->authorizeAccess();
20
21
// Display view
22
return view('front.infopage', compact('page'));
23
}
24
}
Copied!
authorizeAceess() will check if user is logged in, has one of the assigned access roles and abort with 401 unauthorized error if not.
Last modified 1yr ago