Joshuyo

Joshuyo

Member Since 2 Years Ago

Experience Points 410
Experience Level 1

4,590 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 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

06 May
1 month ago

Joshuyo left a reply on Slack Warning

public function toSlack($notifiable)
    {
        return (new SlackMessage)
            ->content('One of your invoices has been paid!');    
    }
04 May
1 month ago

Joshuyo started a new conversation Slack Warning

I am using laravel version 5.8. What is the proper way to send a warning message to slack? The following code does not generate a warning message...

public function toSlack($notifiable)
    {
        return (new SlackMessage)
            ->content('One of your invoices has been paid!')
            ->warning();
    }
30 Jul
10 months ago

Joshuyo left a reply on Laravel Route Conflict

The order of the routes matter. Moreover, if you want to use "where", it only works with regular expressions at least in 5.6.

Here is how I made it work for me:

// any string not starting with "search" word
Route::get('/articles/{article}', '[email protected]')->name('articles.show')->where('article','^(?!search).+');

Joshuyo left a reply on Laravel Route Conflict

Your first suggestion is working fine, however the second one is throwing an error.

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

    /**
     * Throw a method not allowed HTTP exception.
     *
     * @param  array  $others
     * @return void
     *
     * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
     */
    protected function methodNotAllowed(array $others)
    {
        throw new MethodNotAllowedHttpException($others);
    }
29 Jul
10 months ago

Joshuyo started a new conversation Laravel Route Conflict

Here are my routes in web.php file:

Route::get('/articles', '[email protected]')->name('articles.index');
Route::get('/articles/{article}', '[email protected]')->name('articles.show');
Route::get('/articles/search', '[email protected]')->name('articles.search');

"http://localhost:8000/articles/search?key=google" triggers show method instead of intended search method.

Any suggestions?

26 Jun
11 months ago

Joshuyo left a reply on How To Filter Intermediate Table

Tried that, but then, JSON structure changes...

Joshuyo left a reply on How To Filter Intermediate Table

Thanks for the prompt response but this does not return what I want. I'am trying to get the articles which were assigned a specific tag.

Here is the sql equivalent of my desired query:

select a.*, t.* from articles as a
join article_tag as at on a.id = at.article_id 
join tags as t on t.id = at.tag_id
where at.tag_id = 7

Joshuyo started a new conversation How To Filter Intermediate Table

Tables:

articles
    id
    title
    name

tags
    id
    name    


article_tag
    article_id
    tag_id

Article model:

public function tags()
{
    return $this->belongsToMany('App\Tag','article_tag', 'article_id', 'tag_id')->withTimestamps();
}

Here is how I filter and get results based on title field in ArticleController:

...
$articles = Article::where('title', 'like', '%'.$key.'%')->with('tags')->get();
return response()->json(['result' => $articles]);
...

How can I filter and get results based on article_tag.tag_id? Please note that I need to return the same json structure!

Thanks

21 Jun
1 year ago

Joshuyo left a reply on How To Get Trimmed Value Via Eloquent

Sorry I needed to clarify one thing. Here is the my code:

$records = Article::where('title', 'like', '%'.$key.'%')->get();
return response()->json(['article' => $records]);

After an ajax call, corresponding records are found and returned. Instead of sending the whole content, I would like to send the first paragraph to utilize performance.

Joshuyo started a new conversation How To Get Trimmed Value Via Eloquent

I save blog posts in a table called "articles". Whole post is inserted in column named "content". How can I retrieve sub string of this column via eloquent?

12 May
1 year ago

Joshuyo left a reply on How To Use Laravel Policies Via Middleware In 5.6?

Thanks for the prompt answer.

What about linking custom method names in controller and policy files?

Joshuyo started a new conversation How To Use Laravel Policies Via Middleware In 5.6?

I want to apply authentication to index() method in my PostController.php via policies.

I have created a method called index() in PostPolicy.php as follows:

public function index(User $user, Post $post) { // returns false if the user does not have certain role }

What else I need to do in order to link index methods in my controller and policy files? How I should change my router in web.php? ( current one : Route::get('/posts', '[email protected]')->name('posts.index') )

Thanks

26 Mar
2 years ago

Joshuyo started a new conversation How To Use Deleting Event In Laravel 5.4? (soft Delete)

Here is the first question in my "How to... " series...

https://laracasts.com/discuss/channels/laravel/how-to-use-created-event-in-laravel-54

I add 3 columns, "createdBy, updatedBy, and deletedBy" in each table. When corresponding action is triggered, the fields should be automatically filled in. I prefer to use "soft delete" and added following lines in boot method.


use SoftDeletes;
protected $dates = ['deleted_at'];

public static function boot()
    {
        parent::boot();
        self::creating(function($model){
            $model->createdBy = 1;
        });

    // added lines
        self::deleting(function($model){
            $model->deletedBy = 1;
        });
    }

I tried the following cases but "deletedBy" column was not updated.

Case 1 :

Model::destroy($id);

Case 2 :

Model::where('id', $id)->first()->delete();

Any suggestions?

25 Mar
2 years ago

Joshuyo started a new conversation How To Use Created Event In Laravel 5.4?

I have a column, createdBy (referring to the user ID who creates the record) in each table and would like to populate it within created event. Can anyone provide and example code?