ismaile

ismaile

Member Since 2 Years Ago

Experience Points
112,320
Total
Experience

2,680 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
497
Lessons
Completed
Best Reply Awards
103
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 23
112,320 XP
Sep
21
6 days ago
Activity icon

Awarded Best Reply on Looking For A Recommendation For A No-captcha For Laravel 7

Maybe, you can check this one out then: https://github.com/google/ReCAPTCHA

Besides, it's the Google one and it's a PHP one, so it's not specific to Laravel

Here is a video: https://www.youtube.com/watch?v=mE6NU5ABel4

Sep
19
1 week ago
Activity icon

Replied to 419 Page Expired

I wouldn't redirect to login, I would redirect back instead. Indeed, guest users posting a contact form must be redirected back. However, if an authenticated user performs an action for authenticated users only, there will be the back redirect and the auth middleware can take care of the login redirection.

When the page expires, a TokenMismatchException is thrown.

A TokenMismatchException is also thrown when someone tries to post data to your site from another site.

So, if you don't mind that in both cases, it would redirect to a page, you might override the render method in the app/Exceptions/Handler.php like this:

public function render($request, Throwable $exception)
    {
        if ($exception instanceof TokenMismatchException) {
            return back()->with('custom-error', 'The page has expired');
        }
        return parent::render($request, $exception);
    }

And make sure to add the imports:

use Illuminate\Session\TokenMismatchException;
use Throwable;

Basically, the code says to redirect back when there is a TokenMismatchException and use the default logic from therender method in the parent class otherwise. If this method changes in the framework, you would still be calling it without worrying too much about the changes.

Please note the custom-error sent with the response, indeed, you must let the user know what happened.

Hope this helps

Sep
18
1 week ago
Activity icon

Awarded Best Reply on Meaning And Using Of First()

They will give you the same result but they work differently:

  • $settings = Setting::first(); will return directly the first record from the database running : select * from settings limit 1;
  • $settings = Setting::all()->first(); will call all that returns a collection after running: select * from settings;, then it will call first to take the first element in the collection: https://laravel.com/docs/8.x/collections#method-first

You should use the first one.

Source: I used https://laravel.com/docs/8.x/database#listening-for-query-events to confirm my first thought. toSql gave a different result in this specific use case, it gave select * from settings in both cases

Activity icon

Replied to Issue Grabbing All Emails From DOM String With Match And Regex

You shouldn't put your Regex between double quotes, here is how it should be:

var emailRegex = new RegExp(/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i, "g");
Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

Perfect, you're welcome :)

Activity icon

Awarded Best Reply on One To Many Relationship - Polymorphic Or Regular?

Do you use https://github.com/spatie/laravel-activitylog ?

Since you use a One to Many, I would expect department instead of departments in your with call. I assume you have a method department using belongsTo in your Order model.

Besides, just to confirm it, you use orderBy with variables, I would call the second variable$direction. Indeed, it may be confusing in the future. As you may know, orderBy is used like this: orderBy('name', 'desc')

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

Do you use https://github.com/spatie/laravel-activitylog ?

Since you use a One to Many, I would expect department instead of departments in your with call. I assume you have a method department using belongsTo in your Order model.

Besides, just to confirm it, you use orderBy with variables, I would call the second variable$direction. Indeed, it may be confusing in the future. As you may know, orderBy is used like this: orderBy('name', 'desc')

Activity icon

Replied to Get Array Keys Php/ Laravel

You're welcome, the display might be confusing at the beginning :)

Activity icon

Awarded Best Reply on Get Array Keys Php/ Laravel

Actually, you had the right result, it's just formatted in a different way.

array:2 [▼
  0 => "date"
  1 => "user_id"
]

is equivalent to:

[
  "date",
  "user_id"
]
Activity icon

Replied to Meaning And Using Of First()

They will give you the same result but they work differently:

  • $settings = Setting::first(); will return directly the first record from the database running : select * from settings limit 1;
  • $settings = Setting::all()->first(); will call all that returns a collection after running: select * from settings;, then it will call first to take the first element in the collection: https://laravel.com/docs/8.x/collections#method-first

You should use the first one.

Source: I used https://laravel.com/docs/8.x/database#listening-for-query-events to confirm my first thought. toSql gave a different result in this specific use case, it gave select * from settings in both cases

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

From the information I have so far, I would reach for a Many to Many relationship. Indeed, we can say that a department has many orders and an order belongs to many departments.

Imagine you have a specific order Order, let's call it O.

The order goes from department A to C:

  • A makes the order
  • B verifies it
  • C confirms it.

Now, imagine that you have a One to Many relationship, so, the order belongs to C at the end. But, what if you want to know if it has been processed by A. That's where the Many to Many is handy, you can still get a record that says that it has been processed by A, I'm referring to the pivot table record. Besides, you can put a status flag and for example, a completed_at date which is null by default.

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

I would need to understand the Order business logic. What is the life cycle of an order ? I guess it's initiated by a department but you said that a department should be able to pass it to another one. Could you give me an example ?

An example like the following would be perfect: "IT department makes 5 orders to buy laptops ... " :)

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

From what I understand, I would use a regular one.

I am assuming you have the following tables:

  • employees or users
  • departments
  • orders

And I am assuming that all departments have the same attributes except for the type: "Sales", "HR", ... So, with a where constraint, you can filter departments and you can get all employees for a specific type of department. As for the orders, it's pretty similar, you can get all orders passed from a specific department and from one to another.

I would have reached for polymorphism in a scenario in which a user works in a Company or a School and each one of them is completely different and each correponding table has its own set of attributes in the database.

Activity icon

Replied to How To Make If Condition In Blade

You are welcome :)

Activity icon

Replied to How To Make If Condition In Blade

I think you should use an @if statement like this:

@if ($post->created_at->format('Y-m-d') === date('Y-m-d'))
<span style="color: #ff3c00" class="blink_me"><i>BARU</i></span>
@endif

date is a PHP function : https://www.php.net/manual/fr/function.date.php When you call it like this: date('Y-m-d'), it returns today's date formatted with Y-m-d and you format your article created_at date the same way

Activity icon

Replied to Get Array Keys Php/ Laravel

I've just installed it and tested it a bit, I love it. Thanks a lot :)

Activity icon

Replied to Get Array Keys Php/ Laravel

@sinnbeck Nice image :)

Activity icon

Replied to Get Array Keys Php/ Laravel

Actually, you had the right result, it's just formatted in a different way.

array:2 [▼
  0 => "date"
  1 => "user_id"
]

is equivalent to:

[
  "date",
  "user_id"
]
Activity icon

Replied to Production.ERROR: DateTime::__construct(): Failed To Parse Time String (30/09/2020) At Position 0 (3): Unexpected Character

I am surprised the following configuration keys are within an array:

    'date_format' => 'd/m/Y',
    'date_format_js' => 'dd/mm/yy',

You should try to put them outside of the array and remove the array.

Activity icon

Replied to Upload Multiple Images

I would recommend to take a look at this tutorial, it looks pretty well explained: https://www.itsolutionstuff.com/post/laravel-7-multiple-file-upload-tutorialexample.html

You should adapt it to your images use case as you did in your HTML with:

accept="image/png, image/jpeg"

and modify the controller validation part:

'images.*' => 'mimes:jpeg,png'

And other details such as your images storage folder.

Activity icon

Replied to Driver [] Is Not Supported. When I Upload A Pic

At first sight, it might be related to the configuration file filesystems.php. I think this can help you: https://laracasts.com/discuss/channels/laravel/driver-is-not-supported-1

Sep
17
1 week ago
Activity icon

Replied to Can Modify Mutli Route GET With One Command

@snapey Yeah, having 2 routes with the same endpoint is clearly irrelevant. Just wanted to point out that detail since we were giving different explanations. When I think about it, this might have been confusing.

Activity icon

Replied to Sort Messages By Date

You are welcome :)

Activity icon

Replied to Can Modify Mutli Route GET With One Command

@snapey I have just tested using the same endpoint and it's the second one that is used. I guess you were thinking about the typical use case posts/{post} vs posts/create

Activity icon

Replied to Can Modify Mutli Route GET With One Command

Actually, if you have 2 routes with the same endpoint, the second one overwrites the first. So, the agenda method is going to be called but the index method never. So, the code is not useful.

However, maybe Route::resource can help you sometimes to avoid to have a lot of route declarations in your route file.

Activity icon

Awarded Best Reply on Sort Messages By Date

Maybe, you can do this in your controller:

$msgs = Message::where('de_user_id', $request->user()->id)->orWhere('para_user_id', $request->user()->id)->get()
// ...

You'll have both type of messages sent and received. Then you'll have to return only $msgs and loop through msgs only in Vue, no need to have 2 loops. Then, you can check at each iteration if the id is equal to the one of the user so that you can put the message to the left or to the right.

Activity icon

Replied to Sort Messages By Date

Maybe, you can do this in your controller:

$msgs = Message::where('de_user_id', $request->user()->id)->orWhere('para_user_id', $request->user()->id)->get()
// ...

You'll have both type of messages sent and received. Then you'll have to return only $msgs and loop through msgs only in Vue, no need to have 2 loops. Then, you can check at each iteration if the id is equal to the one of the user so that you can put the message to the left or to the right.

Activity icon

Replied to Use Data From Config/app In Javascript File

@msslgomez You're welcome. Actually, the variable can have any name but I think App is pretty common

Activity icon

Awarded Best Reply on Use Data From Config/app In Javascript File

In i18n.js, you can use window.App.locale if you use the example above. In this case, App is a global variable. Since it is pretty small, you can put it in your layout master file in the HTML header and it would be available in any JavaScript file.

Is it not what you need ?

Activity icon

Replied to Post Request Return 302

@snapey yeah totally, I focused entirely in the standard non ajax way. You are right, if it's an ajax call, then just return;. Otherwise, the full HTML is returned and it's not useful at all.

Activity icon

Awarded Best Reply on Base Table Or View Not Found: 1146 Table 'web.papans' Doesn't Exist (SQL: Select Count(*) As Aggregate From `papans

@hendrasaputra2323 By default, in Laravel, for a Papan model, the corresponding table should bepapans.

Usually, people leave it in the plural form but you can update the table associated with a model in your Papan Model file:

protected $table = 'papan';

https://laravel.com/docs/8.x/eloquent#eloquent-model-conventions

Activity icon

Replied to Base Table Or View Not Found: 1146 Table 'web.papans' Doesn't Exist (SQL: Select Count(*) As Aggregate From `papans

@hendrasaputra2323 By default, in Laravel, for a Papan model, the corresponding table should bepapans.

Usually, people leave it in the plural form but you can update the table associated with a model in your Papan Model file:

protected $table = 'papan';

https://laravel.com/docs/8.x/eloquent#eloquent-model-conventions

Activity icon

Replied to Base Table Or View Not Found: 1146 Table 'web.papans' Doesn't Exist (SQL: Select Count(*) As Aggregate From `papans

In your database/migrations folder, do you have a file called something like: ...create_papans_table.php ?

Activity icon

Replied to Base Table Or View Not Found: 1146 Table 'web.papans' Doesn't Exist (SQL: Select Count(*) As Aggregate From `papans

Please run php artisan migrate if you have not so that your latest migrations are taken into account.

Activity icon

Replied to Post Request Return 302

First of all, you probably know it, the proper way is with return back();

Here is the back helper definition in the framework:

* @return \Illuminate\Http\RedirectResponse
     */
    function back($status = 302, $headers = [], $fallback = false)
    {
        return app('redirect')->back($status, $headers, $fallback);
    }

It returns a RedirectResponse and by default it uses 302. Now, in practice, after the 302, you'll get a 200 if the target route exists and everything goes well, since it's a redirection.

When you don't use return back();, it's as if you do:

back();
return;

The RedirectResponse object is built at some point with back() but never returned and by default, when there is no return, it's as if the method ends with return; which means, it ends returning null, so nothing went wrong, hence 200 directly.

Activity icon

Replied to Use Data From Config/app In Javascript File

In i18n.js, you can use window.App.locale if you use the example above. In this case, App is a global variable. Since it is pretty small, you can put it in your layout master file in the HTML header and it would be available in any JavaScript file.

Is it not what you need ?

Activity icon

Replied to Use Data From Config/app In Javascript File

A common practice is to send the data you need in an App variable :

// In your blade file
<script>
window.App = {!!
 json_encode([
   'authenticated' => Auth::check(),
   'locale' => config('app.locale')
  ])
!!}
</script>

I added authenticated to illustrate how you could put other information

Otherwise, maybe you can have your localein your html tag:

<html lang="{{app()->getLocale()}}">

Then use something like this in Javascript:

document.documentElement.lang
Activity icon

Replied to Create Popup Tutorial

For a list of available JavaScript libraries, you can check this: https://github.com/sorrycc/awesome-javascript#tours-and-guides That's the section related to tours and guides.

The awesome lists have a lot of nice package/library suggestions.

Activity icon

Awarded Best Reply on Insert Data Duplicate In Table PeopleDuplicate From ControllerPeople

Here is a correction for your code, I haven't tested it:

public function store(Request $request) {
  $people = $request->all();
  $duplicate = People::where('name',$people['name'])->where('surname', $people['surname'])->first();  
  if($duplicate) {
    return response()->json(
      PeopleDuplicate::create([
        'people_id'=> $duplicate->id,
        'name'=> $people['name'],
        'surname'=> $people['surname']
      ]), 201);
    } 
  // ...  
}

It's just a first step, the code can obviously be optimized but you can notice that:

  • request->all() can't be used, you should either use the global helper request() like this request()->all() or the variable $request like this $request->all()
  • since $request->all() returns an array, $people is accessed like this $people['name']

Hope this helps

Activity icon

Replied to Insert Data Duplicate In Table PeopleDuplicate From ControllerPeople

Here is a correction for your code, I haven't tested it:

public function store(Request $request) {
  $people = $request->all();
  $duplicate = People::where('name',$people['name'])->where('surname', $people['surname'])->first();  
  if($duplicate) {
    return response()->json(
      PeopleDuplicate::create([
        'people_id'=> $duplicate->id,
        'name'=> $people['name'],
        'surname'=> $people['surname']
      ]), 201);
    } 
  // ...  
}

It's just a first step, the code can obviously be optimized but you can notice that:

  • request->all() can't be used, you should either use the global helper request() like this request()->all() or the variable $request like this $request->all()
  • since $request->all() returns an array, $people is accessed like this $people['name']

Hope this helps

Activity icon

Replied to Looking For A Recommendation For A No-captcha For Laravel 7

The error Class NoCaptcha not found is due to the usage of NoCaptcha in your blade file. The class is not loaded or doesn't exist.

What does your composer.json look like ?

And more importantly, in your vendor directory, do you have anhskohbo/no-captcha ?

By the way, you can try to run: composer dump-autoload

Activity icon

Replied to Insert Data Duplicate In Table PeopleDuplicate From ControllerPeople

As many frameworks, Laravel uses the MVC pattern and calling a controller from another one is clearly not something you should do. So, you should avoid Option B.

Activity icon

Replied to Looking For A Recommendation For A No-captcha For Laravel 7

That's exactly what I was checking. I was investigating if the package has really been installed properly. You can try the configuration steps and let me know what is the outcome

Activity icon

Replied to Looking For A Recommendation For A No-captcha For Laravel 7

Please run:

php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"

and tell me what happens.

Activity icon

Replied to Looking For A Recommendation For A No-captcha For Laravel 7

Try to replace:

{!! NoCaptcha::display() !!}

with:

{!! Anhskohbo\NoCaptcha\Facades\NoCaptcha::display() !!}

And

{!! NoCaptcha::renderJs() !!}

with:

{!! Anhskohbo\NoCaptcha\Facades\NoCaptcha::renderJs() !!}
Activity icon

Replied to CSFR Token Not Working.

Are you sure ? Instead of fr at the end, it is rf

Activity icon

Replied to CSFR Token Not Working.

I think there is a typo, it's called @csrf

Activity icon

Replied to Looking For A Recommendation For A No-captcha For Laravel 7

Before moving forward, let's do something simple, please run:

composer remove anhskohbo/no-captcha

then when it's done:

composer require anhskohbo/no-captcha
Activity icon

Awarded Best Reply on Translate Show Per View To Show Per API

I would take a look at your route definition, after Route::get, you should have something like:

'articles/{article}'

having {article} is important