laravel


  • Use search terms in eloquent queries for Laravel

    Use search terms in eloquent queries for Laravel

    I needed to make an Eloquent query that could take search terms. The search terms are optional – no search term and the whole dataset is returned. In our particular data model the Users have one or many Associations. So the search term should check for user name, phone, email and association name. In the…

    read more…

  • Impersonate users with Sanctum in Laravel

    Impersonate users with Sanctum in Laravel

    I needed to write a somewhat clean solution to let an admin impersonate other users. Which basically means that one user can appear as another user – without having to get access that users credentials to log in. The most obvious use case for this would be when an admin needs access to a user’s…

    read more…

  • Laravel with SSL through Cloudflare on Heroku.

    Laravel with SSL through Cloudflare on Heroku.

    I deployed a Laravel app on Heroku, using Cloudflare for SSL. As a quick note, here’s how I did it. NOTE: if you’re using Laravel 5.4 or higher it’s forceScheme instead of forceSchema Also, you need to set your Laravel environment variable APP_ENV to production (or at least something else than local). Do this in…

    read more…

  • Serve Laravel to the web

    Serve Laravel to the web

    This will make your Laravel instance available on the web. Make sure your router have port 80 forwarded to your machine. Also make sure no other server applications is blocking the port.

    read more…

  • Add column to table in Laravel

    Add column to table in Laravel

    Create migration in console: Use Schema::table() to access existing table (instead of Schema::create() for creating new tables) Then run migrations:

    read more…

  • Laravel helpful plugins

    Laravel helpful plugins

    Generate Seed from Databasehttps://github.com/orangehill/iseed Generate Migrations from Database:https://github.com/Xethron/migrations-generator

    read more…

  • Get a list of run database queries in Laravel

    Get a list of run database queries in Laravel

    This is great if you want to see what queries are actually run when using Eloquent.

    read more…

  • Log Laravel execution time to console

    Log Laravel execution time to console

    Put this in app/start/global.php to get Laravels execution time to the browser console log. L4 This works with L5:

    read more…

  • (PHP) Allow any delimiter in CSV file

    In a Laravel app I made the users would upload CSV files. The problem was that fgetcsv only allows a single delimiter character, and it needs to be defined. The problem with that is that when a user exports a CSV from MS Excel – it could end up using a wide array of delimiters depending on the locality…

    read more…

  • Test localhost email with a simplified SMTP server

    For checking the emails going out from your local server (without actually sending them). Use papercut. https://papercut.codeplex.com/   If you’re using Laravel, then make sure to setup your app/config/mail.php correctly: ‘driver’ => ‘smtp’, ‘host’ => ‘localhost’, ‘port’ => <your papercut port>, ‘encryption’ => ”,

    read more…

  • (PHP) Eloquent doodles for Laravel

    [php] // Get model by primary key $myModel = MyModel::find($id); //Where can use short syntax for equal comparison. $myModels = MyModel::where(‘someAttribute’, ‘=’, ‘someValue’)->get(); $myModels = MyModel::where(‘someAttribute’, ‘someValue’)->get(); // Delete models $affectedRows = MyModel::where(‘someAttribute’, ‘someValue’)->delete(); // Select distinct $distincts = MyModel::distinct()->select(‘someAttribute’)->where(‘someAttribute’, ‘someValue’)->get(); // Select with Limit and offset $myModels = MyModel::limit(30)->get(); $myModels = MyModel::limit(30)->offset(30)->get(); [/php] Different…

    read more…

  • (PHP) Using route groups in Laravel to protect routes

    To protect routes, in Laravel, from unauthorized visits you can use route groups. All routes in group will be affected by the auth before filter. [php] Route::group(array(‘before’ => ‘auth’), function() { Route::get(‘controlpanel’, ‘CustomerPanel@showPanel’); Route::get(‘secret’, ‘Secret@showSecret’); Route::post(‘setup’, ‘SetupController@doSetup’); }); [/php]

    read more…