I want to perform certain operations with a model in a middleware. Here is an example of what I want to achieve: My question is, how can I retrieve the desired parameter from the $request? Answer
Tag: laravel
Laravel schedular: execute a command every second
I have a project that needs to send notifications via WebSockets continuously. It should connect to a device that returns the overall status in string format. The system processes it and then sends notifications based on various conditions. Since the scheduler can repeat a task as early as a minute, I need to…
Laravel findorfail() redirect
I have the following code : if we have an id in the DB table then that will come up with findorfail(), but if we add not existing id to the url like this : http://NewPro.dev/user-profile/24645645456 Then no query can be found and laravel page comes up. How can I redirect to some route if we have no id? Answer
Laravel :: Best way to update a foreign key
I have this migration file Schema::create(‘table_one’, function(Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->integer(‘table_two_id’)->…
How to implement your own Faker provider in Laravel
I want to create a custom provider for Faker in Laravel (e.g. one for a random building name). Where do I store the custom provider in my application and how do I use it?
Laravel Migration – Adding Check Constraints In Table
I want to create a table in Laravel Migration like this- What I have done is- But I can’t create this- Can anyone please tell, how to implement this CHECK constraints in Laravel Migration ? Answer Adding constraints is not supported by the Blueprint class (at least as of Laravel 5.3), however it is poss…
Laravel seeder for table that is hardcoded
I have several tables in my database that are simply used for reference in my application. For example, a table that has two columns, State and State Abbreviation, and has all 50 states and their abbreviations as rows. I want to write seeders for these tables in Laravel, since I want these tables to exist whe…
Bootstrap modal validation in Laravel
I have a registrarion modal which opens on click. The inputs are validated on the view using required, etc. Thing is, there are other fields (also in other modals I’m not mentionig) in which I validate again rules in my controller. I’ve read that a good way of validating modals is using AJAX. I…
Laravel – delete whole collection
I have images for articles, and when I am updating article I would like to check if the images are the same, if not I would like to delete them but if it is possible I would like to delete the whole collection without another query, something like what I have in the code below $images->delete();. This is m…
How to get last inserted id in Laravel?
Here is my code I want to get last inserted id for particular record. I have tried using Eloquent ORM. but it didn’t work. Any help would be grateful. Thank You. Answer Use insertGetId()