I’m working with a Laravel 8 project and have created a Job that gets processed. I’ve got several functions to extract functionality but am getting the following error: Cannot pass parameter 1 by reference The trace is initially saying on line 65, which would be ‘title’ => $page->header ?? “Page $key” but I’m not sure what I’m missing here? My
Tag: laravel
How to display all nested relations in a eloquent model referencing itself in many to many?
I have a many to many relation in Partners model that is referencing itself. The pivot table partner_owners has owner_id, owned_id, percent So a partner can own another partner and so on. How can I query all the nested relations for a partner without knowing how many levels are there? For example $partner = Partner::where(‘id’, 1)->get(); if this partner is
Laravel error: file_put_contents failed to open stream: No such file or directory
I have uploaded my Laravel project to shared hosting, but upon navigating to the website, i am getting the following error: It seems like it is pointing to a local folder. What can I do to resolve this? Answer It turns out I needed to clear the Laravel cache on the server. I added the following to my routes/web.php file
Undefined index , Unable to fetch columns- Laravel
In the above code, Notifications is the model Name. Getting the error Undefined index: notificationTypeName when trying to access column notificationTypeName of the array $data. dd($data) gives an ouput as below: Answer The all method returns the underlying array represented by the collection: see this : https://laravel.com/docs/8.x/collections#method-all so try with this: with foreach
Laravel SEO friendly URLs
I started learning laravel and couldn’t figure out how to solve a problem. For example if i want to create a route for products i can use a route like below. In this approach we would get something like this localhost/product/macbook-pro. However i want to create a url like localhost/macbook-pro. In my project, where I did this with plain PHP
Can’t get Session in controller
I want to alert notify after sent message! I try to get session message after sent in controller but it not working. here my controller code : Answer Use the helpers: for inserting and making seesion : for catch and using the session :
$.ajax gets a 419 only in safari, works fine with chrome and FF
I have a ajax call on a laravel blade page. This ajax call works find on Chrome and FF but fails with a 419 every time when using safari. I have tried all the solutions mentioned in different threads on stack. my latest iteration of the code looks like the following code below. (it is posting after getting a message
Input Field to Laravel save: store datetime when adding just the date
Goal: have two columns (datetime) save an input field that only takes in date I would like the start date to save 11/11/2021 00:00:00 and the end date 11/12/2021 23:59:59 (only the date can be changed) from a text field that a user can only place a date in the text field: snippet of my store function: the code above
How to sort numbers containing current year in prefix
I am having trouble sorting the job numbers in my project. My client requirement is to store the job numbers in the below format:- For example:- The current year is 2021 so the job number will be like this:- When the year changes it should start again from 1 and so on for the next year. For example:- I had
How to annotate Laravel Collection elements during iteration
I was thinking about how to annotate types in PhpStorm. I believe PhpStorm is using Psalm to resolve types, but I can’t find how to annotate type to get suggestions here: $row in my app will always be Collection object and I want to have it marked somewhere here with annotations. Does anyone have an idea how to accomplish that?