Category : spatie

public function __construct() { $this->middleware(‘auth:api’)->only([‘index’, ‘show’]); $this->middleware([‘auth:api’, ‘role:seeker|admin’])->only(‘store’); $this->middleware([‘auth:api’, ‘role:employer|admin’])->only(‘destroy’); $this->middleware([‘auth:api’, ‘role:admin’])->only(‘update’); } There are three roles in the website, admin, employer, and seeker. I use Laravel Spatie middleware for authorization with the controller constructor. All authenticated users will have access to index() and show() methods. Admin users will have access to all methods. Seekers ..

Read more

I just updated my project’s framework from Version 7 to Version 8 (the laravel’s latest version as of this date). Everything works except for the activity logs that produces this error: IlluminateDatabaseEloquentRelationNotFoundException Call to undefined relationship [user] on model [SpatieActivitylogModelsActivity]. This error only appears after I updated laravel and all of composer dependencies including spatie/laravel-activitylog. ..

Read more

In my RoleAndPermission seeder I have $admin = Role::create([‘name’ => ‘admin’]); Permission::create([‘name’ => ‘create-attribute’]); Permission::create([‘name’ => ‘delete-attribute’]); Permission::create([‘name’ => ‘edit-attribute’]); Permission::create([‘name’ => ‘update-attribute’]); Permission::create([‘name’ => ‘view-attribute’]); Permission::create([‘name’ => ‘store-attribute’]); $admin->givePermissionTo([ ‘create-attribute’, ‘view-attribute’, ‘delete-attribute’, ‘edit-attribute’, ‘update-attribute’, ‘store-attribute’ ]); I have created AttributePolicy { return $user->hasPermissionTo(‘view-attribute’); } And in Auth service provider gate { $this->registerPolicies(); Gate::define(‘view-attribute’, [AttributePolicy::class, ..

Read more

i have separate front-end(vuejs app) and backend (Laravel). I m thinking to implement roles and permission using Spatie pacakage since i m using vue it seems difficult for me for its implementation.On implementation only on laravel was quite easy. it would be helpful more if anyone has done similar stuffs and its open source and ..

Read more

i use spatie/regex laravel package for find images in output of FeedReader public function index(News $news) { $feed = Feeds::make(‘http://cyberbannews.com/rss.xml’); $items = $feed->get_items(); foreach( $items as $key => $item ) { echo $title = $item->get_title(); echo ‘<br>’; echo $link = $item->get_permalink(); echo ‘<br>’; echo Regex::match(‘/jpg/’, $item); } // return view(‘news.index’, compact(‘news’)); } rss: http://cyberbannews.com/rss.xml but ..

Read more

I am using Spatie media library to manage media in my laravel app. The issue is it generates oversized images even if the uploaded file is small which results in pixelated images. <?php namespace App; use IlluminateDatabaseEloquentModel; use SpatieImageManipulations; use SpatieMediaLibraryHasMedia; use SpatieMediaLibraryInteractsWithMedia; use SpatieMediaLibraryMediaCollectionsModelsMedia; class Post extends Model implements HasMedia { use InteractsWithMedia; public ..

Read more

So i have added the role Super Admin and assigned that role to my own user. I have also put this piece of code in my own as shown in the documentation: public function boot() { $this->registerPolicies(); // Gate::after(function ($user, $ability) { return $user()->hasRole(‘Super Admin’) ? true : null; }); } But even after following ..

Read more

i am trying to upload backup on google drive using laravel spatie package i followed these steps https://gist.github.com/sergomet/f234cc7a8351352170eb547cccd65011 my backup is created successfully g-drive is integrated successfully but when perform action backup:run it gives this error mostly file not found and in the last it says backup failed because: unlink C:xampphtdocsnewfolderstorageapp/backup-temptemp20-11-07-20-06-19.zip) resource temporarily unavailable and ..

Read more

My Model Structure: namespace AppModels; use IlluminateDatabaseEloquentModel; use SpatieMediaLibraryHasMedia; use SpatieMediaLibraryInteractsWithMedia; use SpatieMediaLibraryHasMediaInterfacesHasMediaConversions; class Profile extends Model implements HasMedia { use InteractsWithMedia; protected $fillable = [‘user_id’,’avatar’,’first_name’,’last_name’,’about’,’job_title’,’company’,’phone’,’country’,’state’,’city’,’industry’,’sub_industry’,’linkedin’,’website’,’youtube’,’facebook’,’instagram’,’twitter’ ,’membership’,’pending’]; public function getAvatarAttribute() { return $this->getMedia(‘images’)->last(); } } My View Structure <img src="{{$user->avatar->getUrl()}}" alt="" class="d-block ui-w-100 rounded-circle"> My Controller code $profile = Profile::create([ ‘avatar’ => $file, ]); $profile->addMedia($request->image) ..

Read more

I want to list in a <select> all users with specific role doctor, i’m using laravel spatie library <label for="select_doctor">{{__("Select doctor") }}</label> <select name="select_doctor" id="select_doctor" class="form-control"> <option value="" selected disabled>—– * —-</option> @foreach (AppUser::all()->hasRole(‘doctor’) as $doctor) <option value="">{{ __($doctor->person->name) }}</option> @endforeach </select> But I get this error Method IlluminateDatabaseEloquentCollection::hasRole does not exist Sourc..

Read more

i’m filling a table with users information now I want to get his role too, i’m using Spatie/permission library <thead> <tr> <th>Name</th> <th>Last name</th> <th>E-mail</th> <th>Role</th> <th>Status</th> <th>Edit</th> <th>Delete</th> </tr> </thead> <tbody> @foreach (AppUser::all() as $user) <tr> <td>{{ __($user->person->first_name)}}</td> <td>{{ __($user->person->last_name) }}</td> <td>{{ __($user->email) }}</td> <td>{{ __() }}</td> <td>{{ __($user->active) }}</td> <td><button class="edit btn btn-sm ..

Read more

I’m using laravel 8 and I’m trying to use SpatieAnalytics, but I’m getting this error Non-static method SpatieAnalyticsAnalytics::fetchMostVisitedPages() should not be called statically I’ve tried what people have suggested, but I don’t know if I’m missing something. So I’m hoping someone can check it out and let me know. Here is my code <?php namespace ..

Read more

I’m trying to get the authenticated user object from the request with roles. I’m using Spatie and Laravel 8. Getting User object from request like so $request->user()->getRoleNames()->pluck(‘name’); return $request->user(); Returns { "id":1, "name":"User name", "email":"User email", "email_verified_at":null, "company":"–", "phone":"–", "created_at":"–", "updated_at":"–", "roles":[ { "id":1, "name":"Super Admin", "guard_name":"web", "created_at":"–", "updated_at":"–", "pivot":{ "model_id":1, "role_id":1, "model_type":"AppModelsUser" } } ..

Read more

I’m trying to install library 7 version into laravel v8.10.0. here is my configurations PHP : 7.3 Laravel: 8.10.0 I have run following command : composer require "spatie/laravel-medialibrary:^7.0.0" But its giving following error: Problem 1 – Conclusion: don’t install laravel/framework v8.11.2 – Conclusion: don’t install laravel/framework v8.11.1 – Conclusion: don’t install laravel/framework v8.11.0 – Installation ..

Read more