zach.codes

Share this post

User's avatar
zach.codes
Useful Laravel Snippets
Copy link
Facebook
Email
Notes
More

Useful Laravel Snippets

Zach Silveira
Nov 19, 2016
∙ Paid

Share this post

User's avatar
zach.codes
Useful Laravel Snippets
Copy link
Facebook
Email
Notes
More
Share

Laravel has a ton of useful features built in. Most of the documentation however, is geared towards a classic application setup. They assume you're going to use Laravel's own view system. These snippets I'm about to share are a valuable addition to any app, but may be geared towards those who have Laravel act as an API and nothing more.

With that being said, I've only been working on Laravel apps for a short time. These are just a few of the coolest things I have come up with in the past couple months. As I work more with Laravel, I'll be updating this post :)

CORS middleware

If you're using laravel as an api, you probably need to setup CORS.

Create a new file: app\Http\Middleware\Cors.php

<?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next(…

Keep reading with a 7-day free trial

Subscribe to zach.codes to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zach Silveira
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More