Laravel OrWhereNull giving wrong results

I have this long query builder where I am basically searching a table and then filter the results based on the passed query strings: $projects = Listing::query() ->when(request(‘q’), function($builder) { $builder->searchQuery(request(‘q’)); }) ->when(request(‘tags’), function($builder) { $tags = request(‘tags’); $builder->whereHas(‘tags’, function($builder) use ($tags) { $builder->whereIn(‘name’, $tags); }); }) ->when(request(‘categories’), function($builder) { $categories = request(‘categories’); $builder->whereHas(‘categories’, function($builder)… Read More Laravel OrWhereNull giving wrong results

Can WhereHas Preformance be batter

Hello I have a Table With millions of records and I’m Trying To Get Model Data By Relation but it’s too slow using where has My Code V1 $influencers = Brand::query()->with(‘campaignBrandInfluencers.influencer’, ‘campaignBrandInfluencers.campaign’)->whereHas(‘campaignBrandInfluencers’, function ($q) { $q->whereIn(‘status’, [CampaignCases::VISIT, CampaignCases::CONFIRMATION, CampaignCases::COVERAGE]); $q->whereHas(‘influencer’, function ($q) { $q->whereNull(‘deleted_at’); }); $q->whereHas(‘campaign’, function ($q) { $q->where(‘status’, 1); }); })->coverageFilter($filter)->orderBy(‘id’, ‘desc’)->paginate(10); i… Read More Can WhereHas Preformance be batter

Laravel eloquent model how to pass in value from function inside controller to render()

How can one pass in the value from a function inside a controller to the render()? For example: class NewClass extends Component { // $a is being passed in. Already defined public function DoSomething($a){ return $a; } public function render() { return view(‘FirstPage’, [ ‘posts’ => NewModel:: // HOW TO PASS IN value of $a… Read More Laravel eloquent model how to pass in value from function inside controller to render()

Laravel Eloquent how to use && or AND inside single WHERE clause

I am trying to make a query using Eloquent Model in Laravel. My original query does not work Query1::where(‘Course_ID’, ‘=’, $request->FLA) ->where(‘Date’, ‘=’, Carbon::today()) I would like the query to include both inside of a single WHERE, akin to: Query1::where(‘Course_ID’, ‘=’, $request->FLA && ‘Date’, ‘=’, Carbon::today()) Is this possible? >Solution : You can use: Query1::where([… Read More Laravel Eloquent how to use && or AND inside single WHERE clause

Using laravels built in UUID doesnt work with route model binding

I am using Laravel 10 … I have setup my project to use Laravel’s inbuilt UUID. In my post model im using the use HasUuids; trait and importing use Illuminate\Database\Eloquent\Concerns\HasUuids; In my migration im setting it up as follows; $table->uuid(‘id’)->primary(); This seems to all be going to plan, posts get saved with a UUID etc… Read More Using laravels built in UUID doesnt work with route model binding

how display data in laravel from multiple values id in database with urls

i have a problem, how to get there are multiple in database values. I used this method it didn’t work : Route::get(‘/users/{id}’, function ($id) { $user = User::where(‘id’, [$id])->get(); return $user; }); I used this method successfully : Route::get(‘/users/{id}’, function ($id) { $user = User::where(‘id’, [1, 2])->get(); return $user; }); i want to display the… Read More how display data in laravel from multiple values id in database with urls

I can't delete or restore a record on composite primary key

I have model with the following primary key use HasFactory, SoftDeletes; protected $table = ‘requests’; protected $primaryKey = [‘request_id’, ‘user_id’]; public $incrementing = false; protected $keyType = ‘string’; protected $fillable = [ ‘request_id’, ‘user_id’, ]; protected $hidden = [ ‘created_at’, ‘updated_at’, ‘deleted_at’, ]; and I run the controller of the following public function store(int $request)… Read More I can't delete or restore a record on composite primary key

Laravel resource not showing "total" attribute inside "meta" when returned as json response

in my Laravel application I created this resource collection using artisan and leave as default: class QuestionResourceCollection extends ResourceCollection { public function toArray($request) { return parent::toArray($request); } } in my controller I’m using the index function to retrieve data from the database and then paginate it using cursor pagination like so: public function index() {… Read More Laravel resource not showing "total" attribute inside "meta" when returned as json response

Eloquent get deeper relation where column

I am trying to get all relations where a column has a specific value. I have 3 models: Productions ProductionPackages ProductionProducts The relationships: 1 Production can have multiple ProductionPackages and 1 ProductionPackages can have multiple ProductionProducts. My goal: I want a list with all ProductionProducts where the supplier_id equals a id. The problem: The production… Read More Eloquent get deeper relation where column