Laravel Eloquent – Where In All

You’ll have to add multiple whereHas for that: $query = User::with(‘activities’); foreach($selectedActivities as $activityId){ $query->whereHas(‘activities’, function($q) use ($activityId){ $q->where(‘id’, $activityId); }); } $userByActivities = $query->get();

How to setup conditional relationship on Eloquent

Lets take a different approach in solving your problem. First lets setup relationship for the various models respectively. class User extends Model { public function agentProfile() { return $this->hasOne(AgentProfile::class); } public function institutionProfile() { return $this->hasOne(InstitutionProfile::class); } public function schoolProfile() { return $this->hasOne(SchoolProfile::class); } public function academyProfile() { return $this->hasOne(AcademyProfile::class); } // create scope to … Read more

Laravel: Change base URL?

First change your application URL in the file config/app.php (or the APP_URL value of your .env file): ‘url’ => ‘http://www.example.com’, Then, make the URL generator use it. Add thoses lines of code to the file app/Providers/AppServiceProvider.php in the boot method: \URL::forceRootUrl(\Config::get(‘app.url’)); // And this if you wanna handle https URL scheme // It’s not usefull … Read more

Laravel 7 Sanctum logout

You need to specify the user : // Revoke a specific user token Auth::user()->tokens()->where(‘id’, $id)->delete(); // Get user who requested the logout $user = request()->user(); //or Auth::user() // Revoke current user token $user->tokens()->where(‘id’, $user->currentAccessToken()->id)->delete(); Update of Laravel 7, 8, 9, 10 : // Revoke the token that was used to authenticate the current request… $request->user()->currentAccessToken()->delete(); … Read more

Is it possible to change props value from method in Vue component?

What you are doing will throw a warning in Vue (in the console). [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “propRoomSelected” The value will actually change inside the component, … Read more

Has many through many-to-many

If you want to have a custom relation, you can create your own extends to Relation abstract class. For example: BelongsToManyThought. But if you don’t want to implement a Relation, I think that it can fulfill your needs : In App\Deal.php, you can combine the solution of @thomas-van-der-veen public function metrics() { return Metric ::join(‘metric_product’, … Read more

Undefined class Route (Laravel in PhpStorm)

Check the Laracasts walkthrough 1) Go to: https://github.com/barryvdh/laravel-ide-helper 2) Click on the gist Generated version for L5: https://gist.github.com/barryvdh/5227822 3) Click on “Raw” to get the current version (as of June 22, 2016 it is): https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php 4) Make sure you’re in your root directory (this is mine) cd /var/www/html/project 5) Download the gist: wget https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php 6) … Read more