vincent15000

vincent15000

Member Since 4 Months Ago

Experience Points
5,720
Total
Experience

4,280 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
4
Lessons
Completed
Best Reply Awards
3
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 2
5,720 XP
Aug
22
2 months ago
Activity icon

Replied to Where Query With Multiple Conditions ?

Good idea, thanks @tykus and @ravish !

Activity icon

Started a new Conversation Where Query With Multiple Conditions ?

Hello,

Is it possible to use the where query with multiple conditions ?

For example I want to query the list of the challenges only if is_visible_at <= Carbon::now() or if is_visible_at = null.

I have tried with where()->orWhere(), but it doesn't work.

Thanks for your answer.

Vincent

Aug
21
2 months ago
Activity icon

Awarded Best Reply on How To Catch 403 Error And Show A Flashy Message ?

I just tried to code a gate and I use it in the controller method. I do not have found another solution. ;)

Activity icon

Replied to How To Catch 403 Error And Show A Flashy Message ?

I just tried to code a gate and I use it in the controller method. I do not have found another solution. ;)

Activity icon

Replied to How To Catch 403 Error And Show A Flashy Message ?

Initially I wanted to use a similar code as this one in the Handler.php exception file.

public function render($request, Throwable $exception)
{
    if ($exception instanceof NotFoundHttpException)
    {
        return redirect(RouteServiceProvider::HOME);
    }
    return parent::render($request, $exception);
}

@snapey I think the best way is perhaps to prevent the user from accessing to the function. Perhaps with a gate ?

Activity icon

Replied to How To Catch 403 Error And Show A Flashy Message ?

@jlrdw I already have tried it ... it doesn't work ... some documents on the web explain that 403 error is not possible with HTTP Exceptions ... I don't understand why.

@snapey I don't show the button ... that's ok ... but I also want to prevent from entering the URL to access the route. What do you mean by saying "ugly FO message" ? I do not find the translation for FO on the web ... ;).

Activity icon

Replied to How To Catch 403 Error And Show A Flashy Message ?

I use a simple link in the webpage.

@if ($game->isOpen())
    <a href="{{ route('player.roadmap', ['game' => $game ]) }}">
        <p class="game title shadow rounded">
            Jouer
        </p>
    </a>
@endif
Activity icon

Started a new Conversation How To Catch 403 Error And Show A Flashy Message ?

Hello,

I know how to show a flashy message. But I don't know how to catch a 403 error.

I have seen various solutions on the web, I have tested them, but no one is working.

I use a policy in a controller method :

$this->authorize('roadmap', $game);

I just want to catch the error and then send a flashy message on the screen.

Thank you for your answer.

Vincent

Activity icon

Replied to Middleware To Test Something Else Than User

No specific need of middleware, but middlewares are very simple to use ;) ...

But it's true that middlewares are only used to test some users properties.

If it's not possible to use a middleware, I will use a policy ;).

Activity icon

Started a new Conversation Middleware To Test Something Else Than User

Hello,

Is it possible to use a middleware to test for example if the registrations are open for a game ?

if (! $game->registrationsAreOpen())
{
	return redirect()->...
}
return $next($request);

I have checked the documentation, but I do not understand how it could be possible to add a parameter like $game (which could be the game that is used at the moment in the code). It seems that the middleware can only use the $user variable to check something about the connected user.

Thanks for your answer.

Vincent

Aug
20
2 months ago
Activity icon

Replied to Custom Policy ?

It works very well ;) ... thank you again.

Activity icon

Replied to Custom Policy ?

Ok thank you, now I have understood ... I test this just now ;).

Activity icon

Replied to Custom Policy ?

@sinnbeck That' not clear to me how I can write it.

$this->authorize('register', $game);

Where do I have to write this line ? Inside the register method in the controller ? Outsite any method in the controller ? But then $game is not known.

Activity icon

Replied to Custom Policy ?

@sinnbeck Thank you

Activity icon

Started a new Conversation Custom Policy ?

Hello,

I have a PlayerController in which I have a register method.

But the register method has to be accessible only if the game is open.

I wanted to check this with a policy. But is it possible to use a policy for that ? When a policy is created, the default method are viewAny, view, create, ... if I want to create another method in the policy file, how is it possible to tell Laravel that this method has to be in relation with my register method ?

Thanks for your answer ;).

Vincent

Activity icon

Replied to Find Lowest File Size In A Directory With Laravel?

I don't think there's a better way ... you always have to list the files and retrieve the size for each one. What you could do is to retrieve the $min value inside your loop.

$min = initialize_to_a_very_big_value;
foreach ($files as $file)
{
	$size = Storage::size($file);
	$min = $size < $min ? $size : $min;
}
Activity icon

Replied to The Same Data Manipulated By Admin And Members

@ravish Thank you ... I have already read the documentation and several youtube videos, but one says something, somebody else says something different, ... it is sometimes difficult to understand what are the good pratices. I am happy to have your point of view. Thank you for your answer, you help me ;) ;) ;).

Activity icon

Started a new Conversation The Same Data Manipulated By Admin And Members

Hello,

If you have for example a table : games. The games data are manipulated by the admin, by the authors, ...

I have read some different opinion about the way to code this.

The admin should not be able to update some game created by any author. But he could have to delete or unpublish a game. So he has some rights on the games which he does not own.

The author has all rights on his own games.

So admin and author have some identical rights on the games and the views are identical.

What is the best pratice ?

Do I have to create a specific controller for the admin with exactly the same code as for the author controller ? Or is it possible to have a unique controller like GameController used by both roles ?

Both solutions work, but there is perhaps a best pratice ?

Thanks for your answer.

Vincent

Aug
18
2 months ago
Activity icon

Replied to Is It Secure To Define Roles In A Config File ?

@jlrdw Why not a roles table ? The only reason is because I don't need to change the roles system.

Activity icon

Replied to Is It Secure To Define Roles In A Config File ?

Thanks I wanted to test it via middlewares. I don't very well the difference between the guards and the policiers. I frequently use middlewares and policies, never guards.

Is the use of guards a better pratice ?

Activity icon

Started a new Conversation Is It Secure To Define Roles In A Config File ?

Hello,

I have to affect some roles to the users. I know the spatie package, but it's not necessary for me.

I ask myself about security.

Is it secure to define some roles in a roles.php file in the config folder ?

Like this one ?

<?php

return [

    'ADMIN' => [
        'title' => 'Administrateur',
        'code' => 1,
    ],
    'SUPERADMIN' => [
        'title' => 'Super-Administrateur',
        'code' => 2,
    ],
    'AUTHOR' => [
        'title' => 'Auteur',
        'code' => 3,
    ],
    'PLAYER' => [
        'title' => 'Joueur',
        'code' => 4,
    ],
    'default' => 4,

];

Or is it better to have a role model (but not necessary for me because there will never be other roles and there is no need for the admin to manage / add / ... the roles from the app) ?

Thanks for your answer.

Vincent

Activity icon

Replied to Scope For Model::all() Method In The Controller

Thanks @automica if it's a best pratice, I do so ! ;) Does it mean a different controller too ? My first idea was to avoid duplicate code ...

Activity icon

Replied to Scope For Model::all() Method In The Controller

@sinnbeck I have already read this, but I'm not sure to understand very well. Can I define a scopeAll() method ?

Activity icon

Started a new Conversation Scope For Model::all() Method In The Controller

Hello,

I have read that it was possible to define some different methods according to the some conditions.

For example I want that all rows are retrieved from the database if an admin is connected, but if an author is connected, he will only see his own rows.

Is it possible to define the all method so that it makes the job ?

So I could write : $games = Game::all(); no worry about who is connected, but when it is an author, all() will return something like :

$game = Game::where('author', $author)->get();

I remember that could be written ... perhaps in the boot method ?

Thanks for your answer.

Vincent

Activity icon

Replied to Query With Multiple Jointures

Do you know what solution is faster ?

Activity icon

Replied to Query With Multiple Jointures

Thank you again ;) @sinnbeck.

I'm always trying to write a query in one unique row, but your solution is easier.

Thanks a lot.

Activity icon

Replied to Query With Multiple Jointures

I just have an idea ... ;).

$clues = Clue::with('challenge', function($query) use($game)
{
   $query->where('game_id', $game->id);
});

But it doesn't work => mb_strpos() error.

Activity icon

Started a new Conversation Query With Multiple Jointures

Hello,

I have an app with games and users. User can register in a game, and unregister if they want.

A game is made of several steps and each step is made of several clues : game => challenges => clues.

So a challenge belongs to one game. A clue belongs to one challenge.

I want to retrieve all clues from a game. How is it possible with queries ? I thought about something like that.

$clues = Clue::where('game_id', $game->id)->get();

But the problem is that I don't have any field named game_id in the clue table. There's only a challenge_id field. And in the challenge table, there's a game_id field.

Do you have any idea how to retrieve all clues from a game ?

Thank you very much ;).

Vincent

Activity icon

Replied to Query To Test If A Row Exists ?

Thank you @sinnbeck that's the good code ! It wasn't soo difficult, but I didn't thought about it ;).

Activity icon

Replied to Query To Test If A Row Exists ?

Thanks for your answer @sinnbeck I already tried the casting, unfortunately this is not the solution.

Activity icon

Started a new Conversation Query To Test If A Row Exists ?

Hello,

I have a many-to-many relationship between two tables.

public function users()
{
    return $this->belongsToMany('App\Models\User', 'users_games')
        ->withPivot('score')
        ->withTimestamps();
}

I want to test if a user is registered in a game.

So I added this method.

public function isCurrentUserRegistered()
{
    $count = $this->withCount(['users' => function (Builder $query)
    {
        $query->where('user_id', Auth::check() ? Auth::user()->id : null);
    }])->get()->first()->users_count;
    return $count === 1;
}

The variable $count contains the right values : 0 or 1.

But the test $count === 1 always returns true.

What's the problem with my code ? I don't understand.

Someone has any idea ?

Thanks a lot ;).

Vincent

Aug
04
2 months ago
Activity icon

Awarded Best Reply on Form And JQuery

A first simplification ...

$("#buttonAddSubstrate").on('click', function(e) {
    e.preventDefault();
    // Get the form to show in the modal window
    $.get(
        $(this).attr("url"),
    )
    .done(function(data) {
        $(".modal-content").html(data);
        // Click on the submit button
        $("#addSubstrateForm").on("submit", function(e) {
            e.preventDefault();
            // Send the fields values to the controller to save the new substrate
            $.post(
                $("#addSubstrateForm").attr("action"),
                {
                    "_token": $("[name='_token']").val(),
                    "title": $("#addSubstrateForm").find("[name='title']").val(),
                },
            )
            .done(function(data) {
                $("[name='substrate_id']").replaceWith(data);
                $("#modalAddSubstrate").modal("hide");
            })
            .fail(function() {
                $("#addSubstrateForm").find("[name='title']").addClass("is-invalid");
            });
        });
        $("#modalAddSubstrate").modal("show");
    });
});
Activity icon

Replied to WYSIWYG Editor ?

Sorry I have not connected here for two weeks. It's ok for me ;). ckeditor is well ;).

Jul
24
3 months ago
Activity icon

Replied to Scheduled Commands

Hello @aurawindsurfing that's the solution with an artisan command ... Thanks ;).

Jul
22
3 months ago
Activity icon

Replied to Scheduled Commands

I wonder if the problem could come from the line I added to crontab.

* * * * * vincent cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

That's in the documentation.

But is >> /dev/null 2>&1 useful ?

Activity icon

Replied to Scheduled Commands

on the command line, I get output yes, and the file is not empty ... the file is empty only when using the scheduling command

no change with the echo command, the file is empty again, the problem doesn't come from mysqldump command

the problem is the same when I run php artisan schedule:run

Activity icon

Replied to Laravel Register Must Have Admin Approve And Role

Hello @andrydox,

You should extend your ChackApproved class.

class CheckApproved extends Middleware
{
	...
}

Then you have to add your middleware to the route middlewares in the Kernel.php file.

protected $routeMiddleware = [
	'auth' => \App\Http\Middleware\Authenticate::class,
	'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
	...
	'approved' => \App\Http\Middleware\CheckApproved::class,
	...
];

Something looks wrong : why do you check if(!Auth::check()->role == 4) instead of if(Auth::check()->role == 4). A mistake : you test twice if role equals 4.

Tell me if this helps you.

Activity icon

Replied to Unable To Alter Foreign Column From Nullable To Not Null In Laravel Migration

Hello @ssquare I had the same problem and the only solution I have found is to refresh the table, it seems to be not possible to update from nullable to not nullable because of constraints : if you have a null column, the you want to update it to not null, it is impossible because there is no value in it.

Activity icon

Replied to Scheduled Commands

@snapey yes if I delete the file, a new one is created ... empty again ;) I have to add a datetime extension to the filename to avoid overwriting, but this is not the problem ... my problem is that the created file is empty ...

Activity icon

Replied to Scheduled Commands

@snapey The result is the same : empty file. Thanks for the spatie db-dumper ... therefore I'd like to understand why it doesn't work with the exec command.

Activity icon

Replied to Scheduled Commands

@aurawindsurfing yes the scheduler is actually running, because the file is created ... but empty ... so the scheduler is running, that's sure

Activity icon

Replied to Scheduled Commands

@aurawindsurfing thank you.

My test is only local for now.

php artisan schedule:run produces the same result : empty file created.

Every minute, it's just for testing, I want to save the database only once a week. ;)

Activity icon

Replied to Scheduled Commands

@mix5003 and @snapey I just tried your solution, it doesn't work, the file is created, but it is empty again

Activity icon

Started a new Conversation Scheduled Commands

Hello,

I have this code.

$command = 'mysqldump --user=dbuser --password=dbpassword --databases dessins > /path/to/save.sql';
$schedule->exec($command)->everyMinute();

On my terminal, the command works fine, but with Laravel scheduler, the save.sql file is created, but it is empty.

I have had a look at the documentation, all seems to be ok in my code.

https://laravel.com/docs/7.x/scheduling#scheduling-shell-commands

Do you have any idea about the problem ?

Thanks for your help.

Vincent

Jul
21
3 months ago
Activity icon

Replied to Laravel Mail

Ok ... I didn't undertand your preview answer very well ... I thought it wasn't possible to send with the client address, but possible to show it ;). Thanks.

Activity icon

Replied to Laravel Mail

Ok that's what I don't want to do.

What I'd like to have is like this.

From : [email protected]

But the mail sent by my email adress (not shown in the mail).

Your solution with replyTo() works when I click on the reply button, but the email doesn't appear in the 'From' field.

Activity icon

Replied to Laravel Mail

Hello @michaloravec, that's a good idea, I have already tested, it doesn't work.

Activity icon

Started a new Conversation Laravel Mail

Hello,

I have tried to send an email with Laravel, all works fine.

The mail is sent from a form completed by a visitor who wants to contact me.

Just one thing I want to do : when I receive the mail, it would be interesting if the 'From' mail was the mail of the person who completed the form (email field).

Here is some code from my Mailable.

public $email;

public function build()
{
    return $this
        ->from($this->email)
        ->markdown('emails.created');
}

And here my ContactController.

public function store(ContactRequest $request)
{
    $mailable = new EmailCreated($request->name, $request->email, $request->subject, $request->msg);
    $mailable->subject($request->subject);
    Mail::send($mailable);
    flashy()->success("J'ai bien reçu votre mail, je vous répondrai prochainement.");
    return redirect()->route('productions');
}

But the 'From' mail when I receive the mail is my mail address used to send the mail and not the mail from the form.

Any idea ?

Thanks for your help.

Activity icon

Replied to Multiple Many-to-many Relation In One Function

Hello @testelek,

Perhaps you could solve your problem before saving your relations. As you save, you could test what id is smaller than the other one, and save the relatioins with first id the smaller and second id the bigger.