Joshuyo

Joshuyo

Member Since 2 Years Ago

Experience Points 2,220
Experience Level 1

2,780 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 17
Lessons
Completed
Best Reply Awards 0
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.

26 Aug
3 weeks ago

Joshuyo started a new conversation Proper Way To Publish Eloquent Model Files

What is the proper way to publish a package specific eloquent model file? There are different methods for loading files not particularly model files. On the other hand using service provider's "publishes" method did not seem to be right because there will be namespace conflict.

Any suggestions? Thanks

03 Aug
1 month ago

Joshuyo left a reply on How To Duplicate Laravel Collection

Thanks for the quick reply. Your answer is enough for the question. What if the query is very long (3 lines) and I try to avoid code duplication, should I still go with the second option (two queries) ?

Joshuyo started a new conversation How To Duplicate Laravel Collection

I would like to get the latest and oldest record in a collection.

(1) $rows = User::all();
(2) $latestRecord  = $rows->latest('updated_at')->first();
(3) $oldestRecord = $rows->oldest('updated_at')->first();  

I am guessing, in line 2, I have changed the collection, "$rows", thus the result is not what I have expected. What is the proper way to use the same collection without manipulating it.

Thanks

06 May
4 months ago

Joshuyo left a reply on Slack Warning

Switching around did not fix the problem...

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

"laravel/slack-notification-channel": "^2.0", requires more examples...

04 May
4 months 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
1 year 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).+');

https://regex101.com/r/VWf9wP/1

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
1 year 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
1 year ago

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

When I try the following eloquent query:

App\Article::with(['tags' => function($query){$query->where('tag_id','=',7);}])->select('articles.id','articles.title')->get();

I am getting all records in articles table.

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 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();

Case 3 :

Db::table('tableName')->where('id', '=', $id)->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?