Monaam

Monaam

Member Since 3 Years Ago

Algiers, Algeria

Co-founder @Brainiac at Algiers, Algeria

Experience Points 2,780
Experience Level 1

2,220 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 18
Lessons
Completed
Best Reply Awards 1
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

31 Aug
1 year ago

Monaam left a reply on Thought On Laravel Certification, Go Or No Go?

Yeah, i'm not interested neither, it's def a no-go.

Monaam left a reply on Validation With Route-model Binding

Maybe use a route pattern?

Route::pattern('id', '[0-9]+');

Monaam left a reply on Routing Conflicts

The ONLY solution is putting the resource generated route before your custom route

30 Aug
1 year ago

Monaam left a reply on DB Deletion Check Before Actual Deletion

I see that you need to overwrite the delete method

public function delete()
{
    if ($this->relation()->count())
    {
        // Redirect or throw exception
    }
    parent::delete();
}

Monaam left a reply on Laravel 5.5 Install Still Confused

Well, i've just been there, it's

composer create-project --prefer-dist laravel/laravel blog "5.4.*"

Check again https://laravel.com/docs/5.4/installation

Monaam left a reply on Laravel 5.5 Install Still Confused

It shouldnt ;)

18 Aug
1 year ago

Monaam left a reply on Where To Store Settings Data

Although cache is a solution, you need to be careful with it, if you flush your cache by accident and you forget to get the parameters again, your code will crash.

I would suggest you use Redis (or any key-value database), If you don't want that, you can still use Eloquent (MySql) and just create a table with two fields, key and value, and handle all the logic in the Eloquent Model.

By that i mean you create a static get method for example SettingsModel::foo('key', 'default_value') and a static set method SettingsModel::setFoo(string: 'key', mixed: 'value')

And in setFoo you delete the old entry if exists and add the new one, or even check if it exists, so you know if update or create.

If you go with option A. make sure you don't add the increments field to avoid any future problems

Cheers

Monaam left a reply on Dynamic Router For Database Driven Website

Hello ! From a first glance, you're problem is more a regex problem, and it's solvable. First you need to declare two route patterns, a categories slug and a product slug to use in our route like so '{categories_slug}/{product_slug}'.

  1. Product slug: it's just a regular slug pattern [a-z0-9-]+, that accepts all letters and characters and has to be at least one character long.
  2. Categories slug: it's a bit tricky this one LOL ! First of all we know that it's a group of slugs separated by slash, so my first thought was ([a-z0-9-]+\/)+ The problem is, while i was getting all the categories, i get the END SLASH with the pattern, and we don't want that, so i've put an optional '?' at the end of the slash and decided to force laravel routing to require a slash between the categories and the product (you'll see that in a moment). The second problem was the grouping, I was getting the last category as a first group, and that plays with laravel's understanding so we need to make sure the regex won't return the last item, we call that "Non-capturing group", so at the end it was ?:[a-z0-9-]+\/?)+. Now let's declare our patterns and route
Route::pattern('categories_slug', '?:[a-z0-9-]+\/?)+');
Route::pattern('product_slug', '[a-z0-9-]+');
Route::get('{categories_slug}/{product_slug}', '[email protected]');

To note that we always need to parse the categories, by that i mean explode the whole string by the slash

class ProductController {
    ...
    public function show($categories_slug, $product_slug){
        $categories = explode('/', $categories_slug);
        ...
    }
    ...
}

Now it's up to you if you want to use a middleware to handle that, or just use the __construct() method, or even leave it in the controllers parameters

Hope i explained it well (I didn't try it tho, so if anything is wrong just ping me)

17 Aug
1 year ago

Monaam left a reply on Auth Middleware Fired Before Other Middlewares?

Okay, I guess i figure it out, and indeed, i was missing something,

in Illuminate\Foundation\Http\Kernel.php you can find a protected variable called $middlewarePriority You just need to overwrite it to whatever order you like in app\Http\Kernel.php

Cheers guys

Monaam started a new conversation Auth Middleware Fired Before Other Middlewares?

Hello folks, so i've been trying to understand something for maybe two hours, and I guess i am missing something.

In my route I have multiple middlewares in this order: web, initialize , auth and can (gate). The initialize middleware do some stuff with the domain and request parameters, nothing big. The problem is, when I access the login page, I can see that Handler->unauthenticated() function being fired before InitializeMiddleware->handle() function. And for my code to work, it has to be in the exact order that i've put it.

So, is this some kind of an error or am I missing something? Thanks folks !

24 Apr
2 years ago

Monaam left a reply on Setting Up More Instances On One Server

Yeah, so that is totally possible, you just need to define multiple database connections in your database.php under the config folder

return [
...
'connections' => [
...
'db1' => [ ... ],
'db2' => [ ... ]
...

And then you can write a migration that detects what subdomain the user accesses and define the connection on the fly.

Route::group(['domain'=>'{subdomain}.stats.com', 'middleware'=>'subdomain',...
...
handle(Request $request, $next){
// Get the subdomain
$subdomain = $request->route('subdomain')
// Put your logic of verification here
// Set the default database connection
config(['database.default' => $yourDatabaseConnection]);
...
23 Apr
2 years ago

Monaam left a reply on Setting Up More Instances On One Server

@Apollyon "instances of laravel" you mean for the stats website?

Monaam left a reply on Skip A Routes Group When Middleware Validation Fails

@martinbean this is a multi-tenant app, it's not a single website, and we provide multiple types of websites, some of the clients belongs to the first type, others to the second, and we want it scalable so we can reach 30 different types. Each type has his routes, but the problem is how Laravel routes works, we catch all clients using their domain name, we cannot add other conditions to the route group

Monaam left a reply on Skip A Routes Group When Middleware Validation Fails

@martinbean the thing is, he might not have an active subscription for the first group of websites, but he has one in the second group I want to skip the whole routes group to the next one

Monaam left a reply on Variable Subdomain Routing

I tried to look for an answer, maybe i have missed something, but the basic stupid idea i got is to create a new helper function, that generate the url with the default subdomain name i don't know if that is an option for you

21 Apr
2 years ago

Monaam started a new conversation Skip A Routes Group When Middleware Validation Fails

Hello hellow ! So i am building a multitenant app, users and accounts are stored in the main database. The app has multiple tenant types, each type uses a different database connection, and the app knows which connection to use with $account->connection Each tenant type has different routes structures, so I've put each tenant routes in a different file under the routes folder

  • routes/main/web.php
  • routes/type1/web.php
  • routes/type2/web.php And mapped them all in the routes service provider. And i am using a middleware for each tenant type.
  • Type1Init
  • Type2Init

For my routes, i use the domain parameter as an point of entry Route::pattern('account_host', '([\da-z\.-]+)\.([a-z]{2,6})+');

And for each folder i use :

Route::middleware(['web', 'type1init'])
             ->namespace($this->namespace.'\Type1')
             ->name('type1.')
             ->domain('{account_host}')
             ->group(base_path('routes/type1/web.php'));
Route::middleware(['web', 'type2init'])
             ->namespace($this->namespace.'\Type2')
             ->name('type2.')
             ->domain('{account_host}')
             ->group(base_path('routes/type2/web.php'));

And in each middleware i verify if the account has a valid subscription, The problem is, when i access an account in the second tenant type, i get errors cause the app only access the first group of routes

My question is, can we use middlewares to skip the first group and goes to the second one? third one?

PS: I know i can use dynamic routes loading, but i actually want to cache all the routes for faster execution, so i am asking for that perticular question :)

Thanks !

31 Dec
2 years ago

Monaam left a reply on My Routes Are Not Working - Looks Like Server Problem

Have you checked mod_rewrite in your httpd.conf file?

Monaam left a reply on Right Way To Manage Vast Database In Laravel

If you want to use Eloquent then Yes, if you're OK with Query Builder then no need. But what I suggest is, you should re-structure your database, 180 isn't a good number to work with

06 Jul
3 years ago

Monaam started a new conversation How To Pass A Domain Variable To All Controller Methods

Hello, I hope you're doing fine, So, I'm working on a project, that gives users a website that have multiple segments, each user gets a subdomain. I could get it working by using Sub-Domain routing, Route Model Binding, and of course by passing the object to the different methods of the controllers

$router->bind('website', function ($websiteValue) {
    return App\Website::where('website', $websiteValue)->first();
});
Route::group(['domain' => '{website}.root.com'], function () {
    Route::get('/', function ($website) {
        //
    });
    Route::get('{slug}', function ($website, $slug) {
        //
    });
});

My question is, can i get rid of the $website variable in these controllers? maybe pass a global variable? Thank you