How to use laravel spatie-permission with laravel 8 and jetstream
I have been trying to add spatie to laravel8 with jetstream but I think there is a conflict between spatie-permission and jetstream is there any way to use spatie with laravel 8 and jetstream?
See also questions close to this topic
-
automatic login from controller in laravel 8
I need to make login exactly as laravel Auth Facades does in the following way. I will have some url say "HOST/makeLogin?someToken=xxtrypturan";
Now in controller I have a function as follow:
$creatorOfTheShop = $user->find($request->get('someToken')); //this will give user from db Auth::login($creatorOfTheShop);
Now I want this login to create web session as laravel does in default login. How can I do so, so that I can use auth guards in routes. I wont have any login page, so I am adopting this approach. Thanks
-
Laravel 8.x - Cache query using with() method
1) A simple code that I use to cache an expensive query is something like:
$query = User::where('id', '=', 3); $cacheKey = md5($query->toSql()); // It is: "SELECT * FROM users WHERE id=3;" $users = Cache::remember($cacheKey, 120, function () use ($query) { return $query->get(); });
the query executed is:
SELECT * FROM users WHERE id=3;
2) Now, when I use the
with()
method, the code will be:$query = User::with('car')->where('id', '=', 3); $cacheKey = md5($query->toSql()); // It is ALWAYS: "SELECT * FROM users WHERE id=3;" $users = Cache::remember($cacheKey, 120, function () use ($query) { return $query->get(); });
the query executed are:
SELECT * FROM users WHERE id=3; SELECT * FROM cars where cars.id in (1, 2, 3, 4, 5, ...);
The problem is that the
$cacheKey
(equal to:$query->toSql()
) doesn't consider the all the Eager Loading queries... and when thewith()
changes, the output is the same.For example, If I run:
$query = User::with('bike')->where('id', '=', 3); $cacheKey = md5($query->toSql()); // It is ALWAYS: "SELECT * FROM users WHERE id=3;" $users = Cache::remember($cacheKey, 120, function () use ($query) { return $query->get(); });
the cache exists and return a incorrect output.
What is the best practice to cache quark using
with()
method?Thank you,
-
credentials do not match our records
I am currently working on POS in laravel 8. I am having an error when I login in that "credentials do not match our records" When I login in through the default Register page than it works fine but when I register through internal panel than the data goes to the database but I face error when I log in.
code for registration through panel: public function store(Request $request) { $users = new User; $users->name = $request->name; $users->email = $request->email; $users->password = Hash::make($request->name); // $users->password = bcrypt($request->name); $users->is_admin = $request->is_admin; $users->save(); if($users){ return redirect()->back()->with('User Created Successfully'); } return redirect()->back()->with('User Failed Created'); } default register code: protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); }
-
laravel spatie database backup to google drive on cpanel
Hi i am using spatie(spatie/laravel-backup) package for database backup. Also using nao-pon/flysystem-google-drive package for google drive upload using laravel schedule command. Here is command code
$schedule->command('database:check')->everyMinute(); $schedule->command('backup:clean')->everyMinute(); $schedule->command('backup:run --only-db')->everyMinute();
When i run php artisan schedule:run on my local then i get a zip file on my google drive.But when i run this on cpanel then i didn't get any file in my google drive. Here is code for cron job
/usr/local/bin/php /home/masumcom/binary.masum3.com/artisan schedule:run
One command run perfectly but other two not working perfectly
$schedule->command('database:check')->everyMinute();
Only this one working perfectly
-
How to hide a whole menu with its submenu if you do not have the permission? Spatie-Menu
I created a sub menu that hides the options of the submenu if I do not have the permission, but it leaves me the name of the menu, I do not know if you understand. I attach images.
User with permission has access to see the Management Report menu. ✔✔
User without permission should NOT have access to see the Management Report menu.
This is the code
->submenu( Spatie\Menu\Link::to('#','<i class="ri-folder-chart-line"></i><span>Reportes Gerenciales</span><i class="ri-arrow-right-s-line iq-arrow-right"></i>') ->addClass('iq-waves-effect'), Menu::new() ->addClass('iq-submenu') ->routeIfCan('view all reports', 'home.salesManager', 'Desempeño de leads') ->routeIfCan('view all reports', 'home.historicalReports', 'Historico de ejecutivo') )
-
Missing page redirector Laravel implements Redirector
I am using spatie missing page redirector https://github.com/spatie/laravel-missing-page-redirector . this libray have interface to implement the interface name Redirector. I wanted to implements the interface to merge both my class(which implements Redirtor) array config/missing-page-redirector.php array but this not working here is my config/missing-page-redirector.php
return [ 'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class, 'redirect_status_codes' => [], 'redirects' => [], ];
below is my class which implements spatie interface Redirector
namespace App\Services; use App\Model\Redirect; use Spatie\MissingPageRedirector\Redirector\Redirector; use Symfony\Component\HttpFoundation\Request; use Illuminate\Support\Facades\Cache; class MyRedirector implements Redirector { public function getRedirectsFor(Request $request): array { // Get the redirects from the config $configRedirects = config('missing-page-redirector.redirects'); // Merge both values return array_merge(['/old/url' => '/new/url'], $configRedirects); } }
Can you please let me know what is problem?
-
custom transition classes don't work on Vue.js
I'm trying to use some transition in my code using Vue.js with Tailwinds. My environment include Laravel Jetstream with Inertia that comes with vue.
I notices that using this form everything work:
<transition name="some-name"> <div v-if="something"></div> </transition>
and this classes in my CSS:
.some-name-enter { transform: translateX(-100%); } .some-name-leave-to { transform: translateX(-100%); } .some-name-leave-active, .some-name-enter-active { transition: all 0.5s ease-in-out; }
but when i try to use this sintax:
<transition enter-active-class="transition ease-out duration-100 transform" enter-from-class="opacity-0 scale-95" enter-to-class="opacity-100 scale-100" leave-active-class="transition ease-in duration-75 transform" leave-from-class="opacity-100 scale-100" leave-to-class="opacity-0 scale-95" > <div v-if="something"></div> </transition>
it is not working.. i just would like to use tailwind classes for the transition, they are very easy to use and there is no need to write lots of rows of css.
i dont know if it is important but i am using vue 2.6.12. thanks in advance for your help.
-
How to link a form with user id - Laravel jetstream
I am using Laravel Jetstream for user registration and I have created a form in the main page but I want the form to be linked with the current user id who is filling the form.
Here is the form code:
Controller:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Enquiry2Model; use Illuminate\Support\Facades\Auth; class Enquiry2Controller extends Controller { function addData2(Request $req) { session_start(); $table= new Enquiry2Model; $table->icnumber2=$req->icnumber2; $table->projectname2=$req->projectname2; $table->why2=$req->why2; $table->pb2=$req->pb2; $table->wb2=$req->wb2; $table->how2=$req->how2; $table->vid2=$req->vid2; $req->validate([ 'file2' => 'required|mimes:pdf|max:4048', ]); $fileName = time().'.'.$req->file2->extension(); $req->file2->move(public_path('/uploads/form2/'), $fileName); $location = '/uploads/form2/'.$fileName; $table->file2=$location; $table->save(); return back() ->with('success','تم تقديم النموذج بنجاح') ->with('file2',$fileName); } }
Model:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Enquiry2Model extends Model { use HasFactory; public $table = "enquiry2"; }
Migration:
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateEnquiry2Table extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('enquiry2', function (Blueprint $table) { $table->id(); $table->string('icnumber2'); $table->string('projectname2'); $table->string('why2'); $table->string('pb2'); $table->string('wb2'); $table->string('how2'); $table->string('file2'); $table->string('vid2'); $table->string('UserId'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('enquiry2'); } }
So how can I link the user ID to this form so they can fill it one time only?
-
API using laravel jetstream and inertiajs for 3rd party
I know that jetstream uses sanctum for authentication, but how does 3rd party application access the api ? For example I have:
web
Route::resource('posts', 'App\Http\Controllers\PostController');
PostController
public function index() { return Inertia::render('Post/Index', [ 'posts' => Post::all(), ]); }
This works fine for the application itself but how does for example Postman access the api? The docs explained to uncomment several things in the config Jetstream : https://jetstream.laravel.com/1.x/features/api.html. The confusing part for me is, the index() method is returning an inertia page, so if postman/3rd party access it wouldn't they get the page as a response?
So do we need to make a separate method that returns only the data for 3rd party apps like:
public function index() { return Post::all(); }
and should it be placed in the api routes instead of web routes ?