I have hasMany relationship in my User model; I need to get a foreign id in Eloquent data Controller; Expected output; 1 How can I get the foreign key? Answer You can do the following. Since posts has hasmany relation so it return collection of object even though you have one item in posts. or If you still need one
Tag: laravel
Insert an array using seeders with laravel
Hi I want to insert this array using seeders into Laravel framework: I read that I can do it this way: But I want to insert these countries in the column name of my table: I don’t want to do it manually, I want to insert the array of above completely. Thank you so much. Answer Try this solution
Laravel 8: Symbolic Link not appearing in public
I have a problem with symlink. after I run this command php artisan storage:link the uploaded images are showing in the public and storage folder. I can display my img by using this code but after a day the shortcut of the images folder in public has gone and when I run the php artisan storage:link it says it has
How to add a link to route to another page in laravel
I have a view page which i need to add a link to redirect the user to a booking page. I’m not so familiar with PHP so any guides would be helpful. This is the table i have, and i need to add a link next to the of Available to redirect to another page called “quickbookingmodal.blade.php”. This file is
Custom validation not calling the passes() function
I am trying to make a validation that will check whether at least one item is provided in an array following the steps in Custom Validation Rules Routes.php ValidateArrayElementRule.php ExamPaperQuestionsController.php In my test file I have ExamPaperQuestionStoreRequest.php The test is failing Expected status code 422 but received 201. I can see the text “HERE” is logged but “there” is not.
How to solve the @json Blade directive red underline on VSC?
This variables are working perfectly, I wonder why are they with a red underline. Anyone knows how to correct this? Error msg Answer Since VSCode doesn’t ship intellisense for [blade] template files in default, we need to install extra extensions for correct grammar checking and snippets support for .blade.php files. Here are some of them onecentlin.laravel-blade * works best for
SQL error is thrown when laravel pagination is used
The problem is that I have made a relationship between 3 tables and I want to list the result in the view by grouping it only by barcode. My controller function is as follows; When I run the code in this way, the first page comes up, when I try to go to the next page, I get the following
Laravel 8: How to validate entering dimensions
I have a form and there is a field in this form called dimensions and users MUST enter a value like this: 10x10x10 So I am separating length, width and height by x. But now I don’t know how to make this validation with Laravel: So the question is: How can I force users to separate each dimensions by writing
How to redirect a user to different dashboards based on a level field in the ”’users”’ table in Laravel Breeze?
Please forgive me if my question is too generic but I am at my wits end. I have a users table with a level field as shown given below: $table->unsignedSmallInteger(‘level’)->after(‘password’); I want to redirect the user to different dashboards based on the value of the level field. For example for level 0 user admindashboard for level 1 user userdashboard I
Unique validation with 2 columns – Laravel 8.x
I’ve been trying make my validation so that an extension must be unique to it’s own company but not to other companies. Here is my DB table: And my validation rule looks like this: But still I got errors saying that the extension number is already taken. It seems that the Unique rule doesn’t accept multiple columns, only one. Is