SilenceBringer

Member Since 5 Years Ago

Experience Points
152,220
Total
Experience

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
785
Lessons
Completed
Best Reply Awards
119
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.

  • Community Pillar

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

Level 31
152,220 XP
Feb
26
11 hours ago
Activity icon

Replied to Is There A Way To Have Both The V-model And Value?

Hi @ifrit you have a loop for products v-for="product in products" but try to assign every product.name to the same datav-model="productName"? Something goes completely wrong in your case. Try to describe more details what you want to do

I see you are trying to get summary for product, but - for which one? products array can contains many different products

Feb
25
1 day ago
Activity icon

Replied to How To Automatically Add A Row Number

Hi @glitter grace try something like

<tr v-for="(product, index) in products" >
    <td>{{ index + 1 }}</td>
    <td>{{ product.name }}</td>
</tr>
Activity icon

Replied to Many To Many How To Salve?

Hi @wgerenutti please pay attention to this section of documentation. Save data for belongsToMany relations works different way then others

Activity icon

Replied to How To Validate Request Using Ajax?

@nickywan123 let's check what you have in request

public function update(Request $request,Reply $reply){
    dd($request->all());
    // ...
}
Activity icon

Replied to Login Through API

@afoysal possible just typo? use Auth::check() (lower case for check)

Feb
22
4 days ago
Activity icon

Replied to Count(): Parameter Must Be An Array Or An Object That Implements Countable On Laravel Relationship

@simonangatia fisrt of all, you have N + 1 problem, and need to read about eager loading

And - you example do not tells anything. Please, can you show your Forum model?

Activity icon

Replied to Eloquent Condition Inside Nested With()

@mansoorkhan8 that'ss great. Please consider to making response as best answer to mark conversation as "Solved"

Activity icon

Replied to Query As A Function Inside Model For Reusing

I prefer to use dependency injections (it means - via contructor)

Activity icon

Awarded Best Reply on Query As A Function Inside Model For Reusing

Hi @ramniksingh first of all, query builder have pluck method, so, you can just call in controller

$sections = Section::pluck('sname', 'id');

now your questions

  1. No. Scopes are for scoping query, not returning the result, so, your way to use scopes is wrong
  2. Sure. But for simple queries like Section::pluck('sname', 'id') - it's ok to repeat
  3. a. You can specify methods in your Model directly (if is small application) b. You can use Repository layer c. You can create separated Query class
Activity icon

Replied to Query As A Function Inside Model For Reusing

@ramniksingh 3.a. You can inject Model via __construct, for example

//controller
protected Section $section;

public function __construct(Section $section)
{
    $this->section = $section;
}

public function yourMethod()
{
    $sections = $this->section->yourComplexQuery();
}

3.b. For a large projects you Model will grows extremely quick if you'll keep everything (include all the methods) in your model. This way it make sence to move queries in separated layer (repository or queries class)

Activity icon

Replied to Clearing Cache

Hi @ifrit possible something like Redis::eval('flushdb') will do the trick

Activity icon

Replied to Eloquent Condition Inside Nested With()

@mansoorkhan8 I't not possible with default laravel relations, but you can look to this package, looks like it's what you need

Activity icon

Replied to Query As A Function Inside Model For Reusing

Hi @ramniksingh first of all, query builder have pluck method, so, you can just call in controller

$sections = Section::pluck('sname', 'id');

now your questions

  1. No. Scopes are for scoping query, not returning the result, so, your way to use scopes is wrong
  2. Sure. But for simple queries like Section::pluck('sname', 'id') - it's ok to repeat
  3. a. You can specify methods in your Model directly (if is small application) b. You can use Repository layer c. You can create separated Query class
Feb
20
6 days ago
Activity icon

Awarded Best Reply on Get All Films Which Has One Or More Genre

@hovo possible mistake, you call whereHas on coutry instead of genre

Activity icon

Replied to Get All Films Which Has One Or More Genre

@hovo this way I think you example should work. Do you have any problems with it?

Activity icon

Replied to Get All Films Which Has One Or More Genre

@hovo really it's based on your relation and search params. Please show you genre relation on films model, and what the value you have in $request->genre? id of genre?

Activity icon

Replied to Authorization Using Different Policies

@nickywan123 it's convention - using police method with the same name as performed action. Really (as Jeffrey love to says in his video) - who cares? Sometimes (if I have the same authorization logic for all performed actions) I create policy method 'access', so, it make more sence where you check if user has access to model at all, like so

$this->authorize('access', $post);

About using via controller method or model - it's up to you. If your logic is just to abort unauthorized requests - autthorize helper looks more clean. If you want to implement custom logic per action (like flash specific message , redirect to conditional page) you can call it via model to have more flexibility in response processing

Activity icon

Awarded Best Reply on Why UploadFile Function Is Not Working ?

@santoshdc as I see, your function uploadFIle doesn't have return statement, but you expect file_name as the result of the function in controller to set file name

Activity icon

Replied to Get All Films Which Has One Or More Genre

@hovo possible mistake, you call whereHas on coutry instead of genre

Activity icon

Replied to Getting Index Of Posts From Channels User Is Subscribed To

@thebigk it calls whereHas of each relation in sequence - step by step.

Activity icon

Awarded Best Reply on Getting Index Of Posts From Channels User Is Subscribed To

Hi @thebigk try something like

Channel::whereHas('subscribers', function ($query) {
    $query->where('user_id', auth()->user()->id);
})
    ->with('posts')
    ->get();

or if you need to sort (or paginate) by posts

Post::whereHas('channel.subscribers' => function ($query) {
    $query->where('user_id', auth()->user()->id);
})
    ->with('channel')
    ->get();
Activity icon

Replied to Getting Index Of Posts From Channels User Is Subscribed To

Hi @thebigk try something like

Channel::whereHas('subscribers', function ($query) {
    $query->where('user_id', auth()->user()->id);
})
    ->with('posts')
    ->get();

or if you need to sort (or paginate) by posts

Post::whereHas('channel.subscribers' => function ($query) {
    $query->where('user_id', auth()->user()->id);
})
    ->with('channel')
    ->get();
Activity icon

Replied to Count(): Parameter Must Be An Array Or An Object That Implements Countable On Laravel Relationship

@simonangatia possible you have accessor like getTopicsAttribute on your forum model?

Activity icon

Awarded Best Reply on Ensure Only Rightful Owner Can Edit A Thread.

@nickywan123 it's authorization in blade, but in controller

public function edit($channel,Thread $thread)
    {
        $this->authorize('update', $thread);

        // authorized
    }
Activity icon

Replied to Ensure Only Rightful Owner Can Edit A Thread.

@nickywan123 it's authorization in blade, but in controller

public function edit($channel,Thread $thread)
    {
        $this->authorize('update', $thread);

        // authorized
    }
Activity icon

Replied to Count(): Parameter Must Be An Array Or An Object That Implements Countable On Laravel Relationship

@simonangatia hasMany relation returns Collection instance. why just not use

{{ $forum->topics->count() }}

If problem still appears, try to dd what you have

// in your blade
@dd($forum->topics)
Activity icon

Replied to Ensure Only Rightful Owner Can Edit A Thread.

Hi @nickywan123 it's great, that you created the policy, but did you call the check? Please, look here to understand how to authorize using policies

Activity icon

Replied to Php Artisan Migrate

@asadali007 I mean - are you sure your mysql root user doesn't have password?

Activity icon

Replied to Weird Js Issue

@omar590 maybe you have some conditional output of partials/scripts?

Activity icon

Replied to Target Class [translator] Does Not Exist.

Hi @bhosted can you show us your test?

Activity icon

Replied to Php Artisan Migrate

@asadali007 the problem is that you can't connect to database - permission denied (as in message). Are you sure your credentials are correct? Are you able to connect to mysql via terminal using this credentials?

Activity icon

Replied to Why UploadFile Function Is Not Working ?

@santoshdc as I see, your function uploadFIle doesn't have return statement, but you expect file_name as the result of the function in controller to set file name

Feb
19
1 week ago
Activity icon

Replied to How To Prevent Duplicate In Loop

Hi @david001 if you just need to output child categories without products data - @snapey is right, grabchild categories filtered usingwhereHas for product from database

If you displays products on this page and just want to have list of child categories on the same page, you can do something like:

@foreach($products->unique(fn ($p) => $p->childcategory->name) as $product)
                        <p>
                         
                            {{($product->childcategory->name)}}
                        </p>
  @endforeach

it should prevent duplication

Activity icon

Replied to Why UploadFile Function Is Not Working ?

Hi @santoshdc your problem is here

$file->save($path."/".$file_name);

$file is uploaded file object, not the model. To store in database you should set value for related model

Activity icon

Replied to Best Way To Create Some Kind Of Audit Records

Hi @boubou I use laravel auditing package to log any actions. Then you can just filter it by user to get recent activities per user.

Activity icon

Replied to Laravel Mass Update Using Foreach Loop

@mozziehin as I see you don't have any unique identifier of variant in data, so, you can map any existing Variant to the one in your data array.

I can see 2 ways:

  1. pass unique identified (id column value, for example) with the data, so you can be able to find correct variant to update
  2. (if you don't have direct relations to variant id in other tables) just remove all existing variants and store new
Activity icon

Replied to Retrive Collection Item, Change It And Prepend It Back Into Original Collection

Hi @guntarv by default eloqent returns collection, so, what's the the problem to just append new one?

$options = Option::all();

$newOption = Option::create([
    'crop' => 'value1',
    'variety' => 'value2',
])

$options->push($newOption);

// or prepend

$options->prepend($newOption);
Feb
18
1 week ago
Activity icon

Replied to Laravel Check Box To Textbox?

Hi @davehetfield can you explain little more? Hard to understand what you need

Activity icon

Replied to Laravel Mass Update Using Foreach Loop

Hi @mozziehin you have a lot of things here

First one - you define Variation $products and

$products = $products::query()->where('product_id', $prod_id)->get();

with the same name, so, on the second loop you'll get an error

second one: you get product on each loop, instead of getting it one time before

third: look at sync method instead of detach and attach

fourth: this step

$products->fill(Arr::only($product, $products->getFillable()));

make no sence, laravel automatically will skip all non-fillable attributes

By the way: possible we have wrong understanding of your relations. Product has many variants? can you show us relations between Product model, variants model, what is options for variant, and ideally how you $data array looks like

Activity icon

Replied to Cron Job To Wget Page That Loads Info From Google Sheets

Hi @ftored I can recommend to you to look at this package to manage your cron

Activity icon

Awarded Best Reply on Redirecting After Login

Hi @ifrit try

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function authenticated(Request $request, $user)
    {
        if ($user->role == 'admin') {
            return redirect(route('home'));
        }
        
        return redirect(route('customer'));
    }
}
Activity icon

Replied to Redirecting After Login

Hi @ifrit try

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function authenticated(Request $request, $user)
    {
        if ($user->role == 'admin') {
            return redirect(route('home'));
        }
        
        return redirect(route('customer'));
    }
}
Activity icon

Awarded Best Reply on How To Get Abbr From DAYNAME Function In Sql

Hi @lgendary you can use DATE_FORMAT function like so:

public function getLoggedInUser()
{
    return Session::selectRaw('DATE_FORMAT(created_at, "%a") as date, COUNT(*) as total')
        ->where('created_at', '>', Carbon::now()->subWeek())
        ->groupBy('date')
        ->oldest()
        ->get();
}
Activity icon

Replied to How To Get Abbr From DAYNAME Function In Sql

Hi @lgendary you can use DATE_FORMAT function like so:

public function getLoggedInUser()
{
    return Session::selectRaw('DATE_FORMAT(created_at, "%a") as date, COUNT(*) as total')
        ->where('created_at', '>', Carbon::now()->subWeek())
        ->groupBy('date')
        ->oldest()
        ->get();
}
Activity icon

Replied to Blade Double Underscore

@froedrick double underscore is translation of the text. So, if you want to use multiple languages - you'll be able to easily define translations for this text

By default (if no translation defined for the current language) it will displays text as it is

Activity icon

Replied to How To Go Back To Active Accordion On Page Refresh

Hi @noblemfd bootstrap uses class show to detect which panel should be opened. So, you just need to pass the identifier which panel you want to show by default from your controller. For example, let's name it $panel

in your controller

return view('your_view', [
    'panel' => 'second',
]);

and if your blade

<div id="collapseOne" class="panel-collapse collapse {{ $panel == 'first' ? 'show' : '' }}">

...

<div id="collapseTwo" class="panel-collapse collapse {{ $panel == 'second' ? 'show' : '' }}">
Feb
17
1 week ago
Activity icon

Awarded Best Reply on How Install Laravel-datatables-oracle Without Jquery ?

@mstdmstd your question sounds strange. yajra/laravel-datatables - backend php package to handle server-side work of DataTables plugin on frontend. alpine/tailwind are frontend js/css packages. So, what you are looking for? Replacement of Datatable plugin with alpine/tailwind?

Just try to google something like datatables alpine tailwind and you will find suggestions like this one and much more