Access query string values from Laravel

For future visitors, I use the approach below for > 5.0. It utilizes Laravel’s Request class and can help keep the business logic out of your routes and controller. Example URL admin.website.com/get-grid-value?object=Foo&value=Bar Routes.php Route::get(‘get-grid-value’, ‘YourController@getGridValue’); YourController.php /** * $request is an array of data */ public function getGridValue(Request $request) { // returns “Foo” $object = … Read more

Set session variable in laravel

The correct syntax for this is: Session::set(‘variableName’, $value); For Laravel 5.4 and later, the correct method to use is put: Session::put(‘variableName’, $value); To get the variable, you would use: Session::get(‘variableName’); If you need to set it once, I’d figure out when exactly you want it set and use Events to do it. For example, if … Read more

How to structure a modular app in Laravel 5?

I seem to have figured it all out. I’ll post it here in case it helps other beginners, it was just about getting the namespaces right. In my composer.json I have: … “autoload”: { “classmap”: [ “database”, “app/Modules” ], “psr-4”: { “App\\”: “app/”, “Modules\\”: “Modules/” } } My directory and files ended up like this: … Read more

Laravel says “Route not defined”

The route() method, which is called when you do [‘route’ => ‘someroute’] in a form opening, wants what’s called a named route. You give a route a name like this: Route::patch(‘/preferences/{id}’,[ ‘as’ => ‘user.preferences.update’, ‘uses’ => ‘UserController@update’ ]); That is, you make the second argument of the route into an array, where you specify both … Read more

My Routes are Returning a 404, How can I Fix Them?

On my Ubuntu LAMP installation, I solved this problem with the following 2 changes. Enable mod_rewrite on the apache server: sudo a2enmod rewrite. Edit /etc/apache2/apache2.conf, changing the “AllowOverride” directive for the /var/www directory (which is my main document root): AllowOverride All Then restart the Apache server: service apache2 restart

How Can I Remove “public/index.php” in the URL Generated Laravel?

Option 1: Use .htaccess If it isn’t already there, create an .htaccess file in the Laravel root directory. Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder) Edit the .htaccess file so that it contains the following code: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)