Browsed by
Category: Laravel

Streamlining API Versioning in Laravel: A Smart Approach to Route Inheritance and Overrides

Streamlining API Versioning in Laravel: A Smart Approach to Route Inheritance and Overrides

A new Laravel install has several route files. The two most widely used route files are routes/web.php and route/api.php. As their names imply, these are for web (browser) routes and API related routes. In this post we’re only going to be looking at the API route. Let’s assume that we have a GET endpoint to get a list of all users in our API. We could do this simply in the route file (typically we’d set up controllers etc but…

Read More Read More

Web sockets | real time communication between front and back ends

Web sockets | real time communication between front and back ends

NOTE: I have a new post in the pipeline about web sockets using Laravel’s Reverb which is new in Laravel 11 as well as Laravel’s echo on the front end. I will include a link to that post here once its up. This is a more general post so perfectly usable in PHP without a framework. Its been a while since I’ve written a post and this is a good one (if I do say so myself!). In today’s fast-paced…

Read More Read More

Laravel Service Container

Laravel Service Container

In the realm of web development, managing dependencies effectively and ensuring code remains flexible and maintainable is crucial. Laravel offers a powerful tool known as the Service Container to address this.

In this post, we’ll delve into understanding the Laravel Service Container, why it’s invaluable, and how it can make your development process smoother. We’ll explore the intricacies of Dependency Injection, the significance of Interfaces, and the convenience of Laravel’s app() helper function.

Laravel belongsToMany relationship

Laravel belongsToMany relationship

There are often times when your data has a “belongsToMany” relationship. Laravel handles this relationship really beautifully! I learn best by example, so we’ll do this post as an example I’m currently working on. In our application we have multiple related websites. Each of these sites stands on its own with users being able to register individually on each site. We wanted to update this so that when a user registers on one site their details are automatically pushed to…

Read More Read More

Creating a new laravel site

Creating a new laravel site

Having installed Laravel you’ll now want to create your first Laravel website. Creating the new Laravel site In the command line navigate to the parent directory which contains all your web projects. On my Ubuntu system my projects are all in /var/www/html, so on the command line: cd /var/www/html Decide on a name for your project. We’ll call ours my-cool-website. Now run the new command from the command line like this: laravel new my-cool-website            …

Read More Read More

Node / NPM to manage JS / CSS in Laravel

Node / NPM to manage JS / CSS in Laravel

To manage your js and css files in Laravel you could place your js and css files in the public directory, but using the /resources/assets folder you can add your js and css (sass or less, etc) in there. You then need to compile these with nodejs and NPM. To install nodejs / npm on Ubuntu you can use sudo apt-get install nodejs Once installed in a terminal window navigate to your Laravel project directory and type: node install Once…

Read More Read More

Installing Laravel

Installing Laravel

Laravel is a PHP framework so we need to start with a L(W)AMP server of some sort. We recommend PHP 7 but from PHP 5.6 will do. Laravel is easiest to install with Composer. Once Composer is installed according to their instructions, we can use it to install Laravel. There are different methods of installing Laravel but I prefer installing it as a global package on the system. To do this, on the command line type: composer global require “laravel/installer”…

Read More Read More