Order By before Group By using Eloquent (Laravel)

I just needed to do something similar with a messages model. What worked for me was applying the unique method on the returned eloquent collection. Model::where(‘toId’, $id) ->orderBy(‘createdAt’, ‘desc’) ->get() ->unique(‘fromId’); The query will return all messages ordered by createdAt and the unique method will reduce it down to one message for each fromId. This … Read more

Laravel 4 removing public from URL

Easiest way is create .htaccess file in your Laravel root with following content: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule> It should be redirected easily. Reference: https://coderwall.com/p/erbaig/laravel-s-htaccess-to-remove-public-from-url

Laravel 5.2 Auth not Working

Laravel 5.2 introduces the middleware groups concept: you can specify that one or more middleware belongs to a group, and you can apply a middleware group to one or more routes By default Laravel 5.2 defines a group named web, used to group the middleware handling session and other http utilities: protected $middlewareGroups = [ … Read more

How to use paginate() with a having() clause when column does not exist in table

You can calculate the distance in the WHERE part: DB::table(‘posts’) ->whereRaw($haversineSQL . ‘<= ?’, [$distance]) ->paginate(10); If you need the distance value in your application, you’ll have to calculate it twice: DB::table(‘posts’) ->select(‘posts.*’, DB::raw($haversineSQL . ‘ as distance’)) ->whereRaw($haversineSQL . ‘<= ?’, [$distance]) ->paginate(10);

Call to undefined method Maatwebsite\Excel\Excel::load()

Version 3.0 of that package doesn’t handle imports yet. Release date for this feature is unknown. See this post for more details: https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551 I suggest you switch to version 2.*. Else you want to continue further ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 . Excel::load() is … Read more

Laravel 5.2 CORS, GET not working with preflight OPTIONS

Clearly not the ideal solution but it WORKS. I’ve added this to the top of my routes.php file: header(‘Access-Control-Allow-Origin: *’); header( ‘Access-Control-Allow-Headers: Authorization, Content-Type’ ); It would be nice to get this working without a hack… alas. UPDATE: It turned out to be IIS related. I ended up setting the headers in the web.config file … Read more

Laravel 5.4^ – How to customize notification email layout?

Run this command php artisan vendor:publish –tag=laravel-notifications php artisan vendor:publish –tag=laravel-mail update for laravel 5.7+ php artisan vendor:publish and then you will get: [<number>] Tag: laravel-mail [<number>] Tag: laravel-notifications and then just type in that number in front to publish the file for editing and then in /resources/views/vendor/mail/html/ you can edit all the components and … Read more