laravel

All my posts about laravel.

Creating a mail driver in Laravel

Over at Sitepoint, Younes Rafie wrote a tutorial on how to create a custom mail driver in Laravel 5.3. In the post he shows some code that can log all email to the database.

One of the many goodies Laravel offers is mailing. You can easily configure and send emails through multiple popular services. ... Laravel also provides a good starting point for sending mails during the development phase using the log driver, and in production using smtp, sparkpost, mailgun, etc. This seems fine in most cases, but it can’t cover all the available services! In this tutorial, we’re going to learn how to extend the existing mail driver system to add our own.

https://www.sitepoint.com/mail-logging-in-laravel-5-3-extending-the-mail-driver/

Read more

How (not) to use accessors in Eloquent

Jarek Tkaczyk wrote a blogpost on the usage of accessors in Eloquent. He demonstrates what could go wrong when using accessors on certain fields.

The moral of the story is, that data handling and its presentation should not go into the same bucket. And the model is that bucket – instead of creating accessors, traits or god knows what for this task, better use decorator (like) pattern where you can do all the necessary work for preparing your data to be displayed in your view, without touching actual values anywhere else.

https://softonsofa.com/they-can-bite-how-not-to-use-accessors-in-eloquent/

Keep this in mind when you should use my pragmatic approach for presenters. Watch out for conflicting names.

Read more

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Simplifying presenters in Laravel original

by Freek Van der Herten – 3 minute read

In the Laravel template that we use to kickstart all our client projects at Spatie, I recently changed the way we handle presenters. Instead of using Jeffrey Way's popular presenter package we now use simple traits. In this post I want to give some background on that change. In case you've never…

Read more

Taking care of backups with Laravel original

by Freek Van der Herten – 8 minute read

A new major version of laravel-backup was recently tagged. This package can backup files and databases of your Laravel app (or any PHP application really). The backup consists of a zipfile containing a dump of the databases and all files that are selected for backup. The package will copy over the…

Read more

A retrospective on creating Laravel Shift

Laravel Shift is a paid service that can upgrade a Laravel project. I've used it a couple of times. Although some manually work is needed to complete the upgrade, it has saved me many hours. The service has recently shifted it's 1000th project, a major milestone. In a post on his blog Jason shares how he started the service and where it's going in the future.

In this post, I want to focus more on reaching the milestone of 1,000 Laravel applications upgraded. This may not sound like many, however for my first SaaS product it marks the achievement of my stretch goal. So allow me to share the most important decision, biggest challenge, and what the future holds for Laravel Shift.

http://jason.pureconcepts.net/2016/09/laravel-shift-1000-applications-upgraded/

Read more

Building a search engine friendly sitemap XML with Laravel

Eric Barnes of Laravel News wrote a good tutorial on how to create a sitemap with Laravel.

A few years ago search engines recommended submitted sitemaps to help with indexing your website and now the importance of this is debatable.

I’m of the mindset creating and submitting can’t hurt, so I spent a little time putting one together and wanted to share how easy this is in Laravel.

https://laravel-news.com/2016/09/laravel-sitemap/

Read more

How to create a most popular list with Laravel and Google Analytics

Over at Laravel News Eric L. Barnes posted a new tutorial on how he used our Analytics package to create a list of most popular posts. Great stuff!

Here on Laravel News, I wanted to generate a list of the most popular posts for the past seven days and display the results from most popular to least popular.

To solve this problem I thought of two solutions. The first is to build my own tracking system so I could keep a count and then use it for ordering. However, that could generate a huge amount of data and it seemed like a solution that an analytics tracking service could handle.

As I was fumbling through the Google Analytics API I found a Laravel Analytics package by Spatie.be that allows you to easily retrieve data from your Google Analytics account and it seemed like the best way to solve this problem. Let’s look at how I used it to generate a list of popular posts here on Laravel News.

https://laravel-news.com/2016/09/most-popular-list-laravel-google-analytics/

Read more

Fixing Laravel Valet on macOS Sierra

I'm one of those people who runs beta software. A short time after the keynote is finished I'll update (or wreck) my phone with the beta version of iOS. My Mac generally gets the beta treatment not much later. Of course there are some risks involved. There's no guarantee that your applications will still work. Though your mileage may vary, it's my experience however that those betas are pretty stable.

With macOS Sierra there was one piece of software that didn't work properly: Laravel Valet. For some obscure reason Valet just stopped working after a couple minutes. The requests just hang. After some time an ERR_CONNECTION_REFUSED was displayed in Chrome. After running valet restart it ran fine for some more minutes. After poking around in the configuration of caddy, the webserver that powers Valet, and the php.ini file I found no solution. A complete reinstall of Laravel Valet did not solve the issue. I learned to live with the problem, regularly running valet restart. I even set up an alias for it.

But luckily Bryce Adams found the solution (Martin Bastien notified me about it). It's very simple: you just have to update the caddy server to the latest version manually. Here are the steps involved:

  1. Download `caddy_darwin_amd64.zip` from Caddy's releases page on GitHub.
  2. Extract the files and rename the main executable `caddy_darwin_amd64.zip` to `caddy`
  3. Copy it over and replace the old `caddy` file in this directory: `~/.composer/vendor/laravel/valet/bin/`
  4. Run `valet restart`
  5. Profit!

I hope this post can help all the crazy ones running beta software.


EDIT on 2016-09-21: alternatively, you could use the dev-sierra branch to get a working version of Valet on macOS Sierra.

EDIT on 2016-09-24: Adam has published a list of common problems and solutions for running Valet on Sierra.

Read more

A package to sync your .env file with .env.example

In a Laravel app most sensitive configuration values, like a db password, are being saved in an .env file. This file usually does not get committed in a git repo. In this way you can share the repo with collaborators without having them to know the sensitive values of your production environment.

The keys of the .env are often saved in an .env.example file that is saved in the repo. This helps you and your collaborators get up to speed quickly when installing the app locally. They can immediately see which environment variables are needed to run the app.

Over time however you might add a variable to .env and forgetting to add it to .env.example. It's a mistake that is easily made, and I have made that mistake many times in the past (sorry co-workers).

A couple of days ago Julien Tant released laravel-env-sync. This package makes sure the .env file is in sync with .env.example. After having installed the package you can run this artisan command to perform the sync:

php artisan env:sync

Thanks Julien for that awesome little package.

Read more

Our dashboard has been updated to make use of Laravel Echo original

by Freek Van der Herten – 1 minute read

A couple of months ago we released a dashboard powered by Laravel, Pusher and Vue.js. In tandem with Laravel 5.3 a new JavaScript library was released called Laravel Echo. This library makes it very easy to work with a service like Pusher. This weekend I took the time to update the dashboard to make…

Read more

Automatically generate a sitemap in Laravel original

by Freek Van der Herten – 7 minute read

Today my company released a package called laravel-sitemap. There are already a lot of excellent sitemap packages out there. They all have in common that you have to manually add links that must appear in the sitemap. With our new package that isn't required. It can automatically build up a sitemap…

Read more

Laracon EU recap day 2

Here's Simon Nicklin's recap of day two of the excellent Laracon EU conference: https://www.linkedin.com/pulse/laracon-eu-2016-conference-day-2-simon-nicklin

Personally I had a great time at Laracon. I couldn't relax that good until after I delivered my own talk. Luckily it went well and I got some good feedback. It was very good to see both new and familiar faces. Most talks were excellent, and the venue was amazing. Just look at this picture:

Laracon

I'll be sure to attend next year's Laracon!

Read more

Debugging collection chains original

by Freek Van der Herten – 2 minute read

A couple of weeks ago I published a blog post on how you can easily debug collections using a dd macro. Meanwhile my company released a package that contains that macro. In this post I'd like to introduce a new dump macro, recently introduced in the package, that makes debugging collection chain…

Read more

Laravel LTS is a Trap

A couple of months ago Jason McCreary, creator of Laravel Shift, wrote down his opinion on the Laravel's LTS release. I couldn't agree more with this piece.

The more developers that get trapped by LTS, the more of a drag it creates on the Laravel community. Potentially having adverse affects on its growth. Using LTS as a minimum compatibility line for a Laravel package or other third-party code is understandable. But freezing your apps to an LTS version is not. Your apps should run the latest stable version of Laravel.

https://medium.com/@jasonmccreary/laravel-lts-is-a-trap-97b1d1103961

Read more

Learn about grant types in Laravel Passport

Laravel Passport is an easy to use OAuth2 server that was released alongside Laravel 5.3. Mohamed Said wrote an excellent guest post at Laravel News about the grant types used in Passport.

OAuth2 is a security framework that controls access to protected areas of an application, and it’s mainly used to control how different clients consume an API ensuring they have the proper permissions to access the requested resources.

Laravel Passport is a full OAuth2 server implementation; it was built to make it easy to apply authentication over an API for laravel-based web applications.

https://laravel-news.com/2016/08/passport-grant-types/

Read more

Laracon EU recap day 1

The Laracon EU conference is happening right now. Talking to other developers is a joy like always, the speakers are great and the venue is amazing. Here's a good recap written by Simon Nicklin of the first day of the Laracon EU conference.

We entered the building and joined the back of the queue. I say we, even though I travelled on my own I already felt part of something. The queue snaked around a mood light corner to the awaiting registration desk where we are split into last name lanes. A pleasant volunteer welcomed me as I showed her my ticket. After a quick flick through the name cards I'm registered. For me this was the start of Laracon EU 2016.

https://www.linkedin.com/pulse/laracon-eu-conference-2016-day-1-simon-nicklin

Read more

How to use WordPress as a backend for a Laravel Application

Recently Eric L. Barnes put a new coat of paint on Laravel News. Behind the scenes there were some changes as well. In a new post he explains how he integrated the Wordpress backend with a Laravel app.

Last week I relaunched Laravel News, and the new site is running on Laravel with WordPress as the backend. I’ve been using WordPress for the past two years, and I’ve grown to enjoy the features that it provides. The publishing experience, the media manager, the mobile app, and Jetpack for tracking stats.

I wasn’t ready to give these features up, and I didn’t have the time to build my own system, so I decided to keep WordPress and just use an API plugin to pull all the content I needed out, then store it in my Laravel application. In this tutorial, I wanted to outline how I set it all up.

https://laravel-news.com/2016/08/wordpress-api-with-laravel/

Read more

Practicing YAGNI

In a new post on his blog Jason McCreary, creator of Laravel Shift, wrote down the summary of his Laracon US talk.

I consider myself a searcher. On a quest to find the Holy Grail of programming practices - that single practice which instantly levels up my skills. While I know this doesn’t exist, I do believe in a set of practices. Recently, I found one to be YAGNI.

YAGNI is a principle of eXtreme Programming - something I practice daily at work. YAGNI is an acronym for You Aren’t Gonna Need It. It states a programmer should not add functionality until deemed necessary. In theory, this seems straightforward, but few programmers practice it.

http://jason.pureconcepts.net/2016/08/practicing-yagni/

Read more