s4muel

Member Since 4 Years Ago

Experience Points
101,600
Total
Experience

3,400 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
506
Lessons
Completed
Best Reply Awards
86
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 21
101,600 XP
Jun
12
12 hours ago
Activity icon

Awarded Best Reply on How To Set CURLOPT_INTERFACE In Laravel HTTP Client?

not sure, but i would try this:

$response = Http::withOptions([
    'curl' => [CURLOPT_INTERFACE => 'xxx.xxx.xxx.xxx'],
])->get('http://example.com/users');
Activity icon

Replied to How To Set CURLOPT_INTERFACE In Laravel HTTP Client?

not sure, but i would try this:

$response = Http::withOptions([
    'curl' => [CURLOPT_INTERFACE => 'xxx.xxx.xxx.xxx'],
])->get('http://example.com/users');
Jun
11
1 day ago
Activity icon

Replied to Why Does This Query In Model Not Working ?

sorry, missed some quotes, post fixed/edited

Activity icon

Replied to Why Does This Query In Model Not Working ?

another shot:

$gpsdata = DB::table('gpstrackerclubs')
->select('id', 'flightnumber', 'timeused')
->whereIn('id', function($query) {
    $query->selectRaw('MAX(id) as id')
        ->from('gpstrackerclubs')
        ->groupBy('flightnumber');
})->get();
Activity icon

Replied to How To Debug On Command Line Using Php Artisan Schedule:run

i would tryLog::debug() instead and examine the log file.

i thought you were talking about jobs, sorry, edited

Activity icon

Replied to Why Does This Query In Model Not Working ?

@birdietorerik, something like this, probably:

$gpsdata = DB::table('gpstrackerclubs')->whereIn('id', function($query) {
    $query->select('id')
        ->from('gpstrackerclubs')
        ->groupBy('flightnumber')
        ->havingRaw('MAX(id)');
})->get();

might need a little bit of tweaking, but try this as a starting point.

Activity icon

Replied to Laravel Horizon - Showing Only A Blank Screen

since the data-is-down-for-maintenance="" is unset, i don't think it is in maintenance. if you inspect network tab in a browser devtools, do you get any 404 or any other suspicious codes?

Activity icon

Awarded Best Reply on Why Does This Query In Model Not Working ?

you cannot select a non-aggregated column that is not part of the group by clause. you can turn off the only_full_group_by but i advise not to.

imagine you have a table like this

| ID | flightnumber | timeused |
|----|--------------|----------|
| 1  | A            | 10       |
| 2  | B            | 20       |
| 3  | B            | 30       |
| 4  | C            | 40       |

if you group by flightnumber, for the flighnumber B it picks the ID = 3 (because it it MAX() - aggregated column), but it cant decide which to pick for a timeused.

if the only_full_group_by is turned off, the result can be that what you want, but be warned that mysql is free to pick any random value from the grouped rows in this case.

i would do this in two steps, first get the IDs only and then do another select that gets all rows with those IDs

Activity icon

Replied to Why Does This Query In Model Not Working ?

you cannot select a non-aggregated column that is not part of the group by clause. you can turn off the only_full_group_by but i advise not to.

imagine you have a table like this

| ID | flightnumber | timeused |
|----|--------------|----------|
| 1  | A            | 10       |
| 2  | B            | 20       |
| 3  | B            | 30       |
| 4  | C            | 40       |

if you group by flightnumber, for the flighnumber B it picks the ID = 3 (because it it MAX() - aggregated column), but it cant decide which to pick for a timeused.

if the only_full_group_by is turned off, the result can be that what you want, but be warned that mysql is free to pick any random value from the grouped rows in this case.

i would do this in two steps, first get the IDs only and then do another select that gets all rows with those IDs

Jun
10
2 days ago
Activity icon

Replied to Using Timestamp With Precision On Already Existing Timestamp Column With No Precision

shouldnt multiplying existing data * 1000 help with it?

May
30
1 week ago
Activity icon

Replied to Encounter Issue When Install Dingo/api Package

Does composer update work fine?

Activity icon

Awarded Best Reply on How To Get The ID Of A Newly Created Instance, Using Factory?

@ivymaster, try calling the factory without the count (omit the 1), otherwise you get a collection instead of PaymentInfo/PriceDetail instance.

$paymentInfo = PaymentInfo::factory()->create();
$priceDetail = PriceDetail::factory()->create();
Activity icon

Replied to How To Get The ID Of A Newly Created Instance, Using Factory?

@ivymaster, try calling the factory without the count (omit the 1), otherwise you get a collection instead of PaymentInfo/PriceDetail instance.

$paymentInfo = PaymentInfo::factory()->create();
$priceDetail = PriceDetail::factory()->create();
May
18
3 weeks ago
Activity icon

Replied to Middleware Auth Error

@bobdebower make sure your middleware is called after the web (group) middleware. because the session (and Auth::user()) is not yet available. i guess.

May
07
1 month ago
Activity icon

Awarded Best Reply on Reset $key In Laravel

i am not exactly sure what you mean. what you need to do? just number the rows in a table? have you come across the $loop blade variable? https://laravel.com/docs/8.x/blade#the-loop-variable

you can use the current iteration number within the @foreach

@foreach($maps as $key => $map)
current iteration: {{ $loop->iteration }}
    @if($map->is_public == 1 || Auth::user()->roles->first()->name == 'super' || $map->admin_id == Auth::user()->id || $map->admins->find(Auth::user()->id) )
		//what do you want to do when the condition is met?
    @else
		//and what to do if not?
        $key
    @endif
@endforeach

you can use @continue and @break directives in the condition to end the loop or skip the iteration

edit: oh, i see, just set new variable and iterate it as you wish

@php($i = 1)
@foreach($maps as $key => $map)
current iteration: {{ $loop->iteration }}
    @if($map->is_public == 1 || Auth::user()->roles->first()->name == 'super' || $map->admin_id == Auth::user()->id || $map->admins->find(Auth::user()->id) )
        //do whatever and iterate the $i
        //..
		row: {{ $i }}
		@php($i++)
    @else
		//...
        $key
    @endif
@endforeach
Activity icon

Replied to Reset $key In Laravel

i am not exactly sure what you mean. what you need to do? just number the rows in a table? have you come across the $loop blade variable? https://laravel.com/docs/8.x/blade#the-loop-variable

you can use the current iteration number within the @foreach

@foreach($maps as $key => $map)
current iteration: {{ $loop->iteration }}
    @if($map->is_public == 1 || Auth::user()->roles->first()->name == 'super' || $map->admin_id == Auth::user()->id || $map->admins->find(Auth::user()->id) )
		//what do you want to do when the condition is met?
    @else
		//and what to do if not?
        $key
    @endif
@endforeach

you can use @continue and @break directives in the condition to end the loop or skip the iteration

edit: oh, i see, just set new variable and iterate it as you wish

@php($i = 1)
@foreach($maps as $key => $map)
current iteration: {{ $loop->iteration }}
    @if($map->is_public == 1 || Auth::user()->roles->first()->name == 'super' || $map->admin_id == Auth::user()->id || $map->admins->find(Auth::user()->id) )
        //do whatever and iterate the $i
        //..
		row: {{ $i }}
		@php($i++)
    @else
		//...
        $key
    @endif
@endforeach
May
05
1 month ago
Activity icon

Awarded Best Reply on Cast To 'array' Not Working

from the documentation: https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting

Attributes that are null will not be cast. In addition, you should never define a cast (or an attribute) that has the same name as a relationship.

Activity icon

Replied to Running Seeders Via Laravel Controllers

@zahidnazirkhan any luck with my suggestion?

Activity icon

Replied to Cast To 'array' Not Working

from the documentation: https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting

Attributes that are null will not be cast. In addition, you should never define a cast (or an attribute) that has the same name as a relationship.

Activity icon

Replied to Running Seeders Via Laravel Controllers

@zahidnazirkhan try running this before Artisan::call('db:seed');:

app('composer')->dumpAutoloads();
May
04
1 month ago
Activity icon

Replied to Nested Validation Returns Fields Which Are Not Validated

there is no parent.secret_password in $validated output when i try that, have a look: https://laravelplayground.com/#/snippets/97036a17-8bdf-45c7-9786-3ff40f2a3bf4

May
03
1 month ago
Activity icon

Awarded Best Reply on How To Use Above Row Data To Add With New Row Stock In Laravel ??

@foreach($action_date as $key => $date)
    <td>{{ $date  }}</td>
    @foreach($products as $product)
        @php
            $buy=//query i have written like Product::where() something like that;
            $sale=//query
//keep the stock info for each product from previous row and update by current +buy and -sale
            $stock[$product->id] = ($stock[$product->id] ?? 0) + $buy - $sale;
        @endphp
        <td>
            {{ $buy}}
        </td>
        <td>
            {{ $sales }}
        </td>
        <td>
            {{-- print the stock value for current product --}}
            {{ $stock[$product->id] }}
        </td>
    @endforeach
@endforeach
May
02
1 month ago
Activity icon

Replied to How To Use Above Row Data To Add With New Row Stock In Laravel ??

@foreach($action_date as $key => $date)
    <td>{{ $date  }}</td>
    @foreach($products as $product)
        @php
            $buy=//query i have written like Product::where() something like that;
            $sale=//query
//keep the stock info for each product from previous row and update by current +buy and -sale
            $stock[$product->id] = ($stock[$product->id] ?? 0) + $buy - $sale;
        @endphp
        <td>
            {{ $buy}}
        </td>
        <td>
            {{ $sales }}
        </td>
        <td>
            {{-- print the stock value for current product --}}
            {{ $stock[$product->id] }}
        </td>
    @endforeach
@endforeach
Activity icon

Replied to Non Problem That's Bothering Me!

heh, really!

weird, that this works:

    /** @var \Illuminate\Contracts\Auth\StatefulGuard */
    $guard = auth('admin');
    $guard->attempt(['xxx'], 'xxx');

but this doesn't

    /** @var \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard */
    $guard = auth('admin');
    $guard->attempt(['xxx'], 'xxx');

probably a bug in the intelephense? have you tried searching here? https://github.com/bmewburn/vscode-intelephense/issues

Apr
19
1 month ago
Activity icon

Awarded Best Reply on What Happens Between A Service Provider And The Routes File?

are your routes cached, by any chance? if so, your routes file is not called.

try clearing the routes cache

php artisan route:clear
Activity icon

Replied to Terminated

terminated

Activity icon

Replied to What Happens Between A Service Provider And The Routes File?

are your routes cached, by any chance? if so, your routes file is not called.

try clearing the routes cache

php artisan route:clear
Apr
16
1 month ago
Activity icon

Replied to Store Data Form Foreach

what exactly should happen? the form itself looks OK (i mean, it should be submitted fine), but:

  • do you really have a POST route named simpan-data.absensi-siswa?
  • does it point to correct controller (or callback)?
  • does the controller/callback process it? how does it look like?
  • what exactly should happen? because the only value sent in form is the absen input (+csrf token, of course). i see a foreach in your blade, but there is no value sent for a $siswa (kind of id, i suppose), so the form for each $siswa is exactly the same
Apr
15
1 month ago
Activity icon

Awarded Best Reply on Countries - States - Cities Seeder (foreach Loop Breaks)

you are missing curly braces in the foreach, add them like so:

public function run()
{
    $countriesname = World::Countries();

    foreach ($countriesname as $countryname) {
        if ($countryname->has_division) {
            foreach ($countryname->children() as $statename) {
                $state = new State;
                $state->name = $statename->name;
                $country = Country::where('name', $countryname->name)->first();
                $state->country()->associate($country);
                $state->save();
            }
        }
    }
}
Activity icon

Replied to Countries - States - Cities Seeder (foreach Loop Breaks)

you are missing curly braces in the foreach, add them like so:

public function run()
{
    $countriesname = World::Countries();

    foreach ($countriesname as $countryname) {
        if ($countryname->has_division) {
            foreach ($countryname->children() as $statename) {
                $state = new State;
                $state->name = $statename->name;
                $country = Country::where('name', $countryname->name)->first();
                $state->country()->associate($country);
                $state->save();
            }
        }
    }
}
Apr
12
2 months ago
Activity icon

Awarded Best Reply on Laravel DOMPDF UTF 8

does your font support those non-english characters? try using DejaVu Sans and check if that works

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <style>
    * { font-family: DejaVu Sans !important; }
  </style>
</head>
Activity icon

Replied to Laravel DOMPDF UTF 8

does your font support those non-english characters? try using DejaVu Sans and check if that works

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <style>
    * { font-family: DejaVu Sans !important; }
  </style>
</head>
Mar
25
2 months ago
Activity icon

Replied to Laravel Fill With Custom Query Fields

the fill() method checks if the field is fillable (or at all guardable, as checked in https://github.com/laravel/framework/blob/5.5/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php#L189 )

since this column doesnt exist in schema, you need to be explicit, either by setting it fillable or not using fill(), try setting it manually

//...
$item->fill((array) $row);
$item->total_amount = $row->total_amount;
Activity icon

Replied to Resource Route "create" - "SQLSTATE[22P02]: Invalid Text Representation"

Route::resource('poll', PollController::class)->only(['index', 'show']);

this creates also a route poll/{poll} (named polls.show, just for reference) and later by this

Route::resource('poll', PollController::class)->except(['index', 'show']);

you want to create (also) a poll/create (named polls.create) but the first one is matched, because it is set up first, and it tries to resolve the create word by a route model binding and bind it to {poll} placeholder.

try switching the order (but be careful not to create another similar problem with this change, since you have another routes in the group). or just try to put the polls.create first and check if this is the problem

Auth::routes();

Route::resource('poll', PollController::class)->except(['index', 'show'])->middleware('auth');
Route::resource('poll', PollController::class)->only(['index', 'show']);

Route::group(['middleware' => ['auth']], function() {
    Route::post('poll/vote/{poll}', [PollController::class, 'vote'])->name('poll.vote');
    [...]
});
Activity icon

Replied to Laravel Fill With Custom Query Fields

check your $fillable and/or $guarded property in the Item model

fill() only works for not guarded (and fillable) attributes. try adding total_amount to fillable

protected $fillable = ['total_amount']; //add to the rest of any existing attributes
Mar
19
2 months ago
Activity icon

Replied to How To Use Multiple Version Of PHP Xampp On Windows

is this of any help? https://stackoverflow.com/a/49586592

not exactly an answer to your question, but since i switched from xampp to https://laragon.org/ some years ago, I am not looking back.

Mar
15
2 months ago
Activity icon

Replied to Adding Comment Id To Thread As Solution

up to where does it work?

public function markAsSolution()
    {
        $solutionId = Request::get('solutionId');
        $threadId = Request::get('threadId');

		//does it get to here and are the variables set? if so, remove dd and move on
		dd($solutionId, $threadId);

        $thread = Thread::find($threadId);

		//is the thread found?
		dd($thread);

        $thread->solution = $solutionId;
		//is the solution relation set up properly? is it an eloquent relationship?

        if ($thread->save()) {
	    	//is the thread saved?
    		dd($thread->refresh());

            if (request()->ajax()) {
                return response()->json(['status' => 'success', 'message' => 'marked as solution']);
            }
            return back()->withMessage('Marked as solution');
        }
    }
Mar
04
3 months ago
Activity icon

Replied to Getting Page To Delay Until File Gets Saved

what does it say? try to dump it

public function createPdf(User $user, Bill $bill)
{
    $pdf = PDF::loadView('pdf.bill-format', ['bill' => $bill]);

	//dump here if pdf is generated ok (examine the dumped object)
	dump($pdf);

    $path = 'users/' . $user->id . '/bills/' . $bill->created_at; //there is no pdf suffix? and the filename can cause name collisions if a user generates multiple pdfs at the same time. should work at least until you make it work

	//dump and die here, the put method should return bool
    dd(Storage::put($path, $pdf->output()));

    return $path;
}

is the pdf generated ok by the loadView()?

is your default disk configured properly? to be sure to use local disk, you might call the disk() method before download() and put()

//...
Storage::disk('local')->download(...);
//...
Storage::disk('local')->put(...);
//...
Mar
02
3 months ago
Activity icon

Replied to Email Verification With Multiple Brokers

i dont think it is needed to differentiate at this level.

it calls the fulfill() method on the EmailVerificationRequest https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/Auth/EmailVerificationRequest.php#L47

that operates on the current user, which is then marked (updated) as verified. or am i missing something?

Activity icon

Replied to Getting Page To Delay Until File Gets Saved

you mess up with the disks and paths a lot. you do not need a sleep.

i suppose you use the default local disk (see .env and config/filesystems.php), if so, you can omit specifying the disk at all. if not, specify according to config using the disk('your-filesystem-disk-name') method

public function downloadPdf(User $user, Bill $bill)
{
    $pdfPath = billService()->createPdf($user, $bill);

    return Storage::download($pdfPath, $bill->filename);
}

//...

public function createPdf(User $user, Bill $bill)
{
    $pdf = PDF::loadView('pdf.bill-format', ['bill' => $bill]);

    $path = 'users/' . $user->id . '/bills/' . $bill->created_at; //there is no pdf suffix? and the filename can cause name collisions if a user generates multiple pdfs at the same time. should work at least until you make it work

    Storage::put($path, $pdf->output());

    return $path;
}
Mar
01
3 months ago
Activity icon

Awarded Best Reply on Artisan Command For Testing Route Matching?

there is no solution out of the box, but it should be fairly simple, if i get that what you need

    $router = Route::getRoutes();
    $request = Request::create('/thing/param1/param2');
    try {
        $router->match($request);
        dump('Route exists.');
    }
    catch (\Exception $e) {
        dump('Route does not exist.');
    }

just wrap that to a command

Activity icon

Replied to Artisan Command For Testing Route Matching?

there is no solution out of the box, but it should be fairly simple, if i get that what you need

    $router = Route::getRoutes();
    $request = Request::create('/thing/param1/param2');
    try {
        $router->match($request);
        dump('Route exists.');
    }
    catch (\Exception $e) {
        dump('Route does not exist.');
    }

just wrap that to a command

Activity icon

Replied to Laravel CRUD Generator Using YML Files

can't help myself, is this a spam? 😅

Activity icon

Awarded Best Reply on Count Column In Hasmany

@lakazai

Post::join('post_view', 'posts.id', '=', 'post_view.post_id')
    ->select('posts.*', DB::raw('SUM(post_view.views) as views'))
    ->orderByDesc('post_view.views')
    ->whereDate('post_view.date', '>=', Carbon::now()->subDays(7)->format('Y-m-d'))
    ->groupBy('posts.id')
    ->first();

https://laravelplayground.com/#/snippets/24ec119f-481d-45cf-8244-94d9c785e053

edit: this works when sql_mode is not set to only_full_group_by

if you need to, either add the columns to the ->select() from the post table you are interested to. (since it is grouped by id, you should safely add what you need

Post::join('post_view', 'posts.id', '=', 'post_view.post_id')
    ->select('posts.id', 'posts.title', 'posts.body', '...', DB::raw('SUM(post_view.views) as views'))
    ->orderByDesc('post_view.views')
    ->whereDate('post_view.date', '>=', Carbon::now()->subDays(7)->format('Y-m-d'))
    ->groupBy('posts.id')
    ->first();

or select just the posts.id and get it in a new query

...
 ->select('posts.id', DB::raw('SUM(post_view.views) as views'))
...
//and then later
$post= Post::find($post_id);
Activity icon

Replied to Count Column In Hasmany

@lakazai

Post::join('post_view', 'posts.id', '=', 'post_view.post_id')
    ->select('posts.*', DB::raw('SUM(post_view.views) as views'))
    ->orderByDesc('post_view.views')
    ->whereDate('post_view.date', '>=', Carbon::now()->subDays(7)->format('Y-m-d'))
    ->groupBy('posts.id')
    ->first();

https://laravelplayground.com/#/snippets/24ec119f-481d-45cf-8244-94d9c785e053

edit: this works when sql_mode is not set to only_full_group_by

if you need to, either add the columns to the ->select() from the post table you are interested to. (since it is grouped by id, you should safely add what you need

Post::join('post_view', 'posts.id', '=', 'post_view.post_id')
    ->select('posts.id', 'posts.title', 'posts.body', '...', DB::raw('SUM(post_view.views) as views'))
    ->orderByDesc('post_view.views')
    ->whereDate('post_view.date', '>=', Carbon::now()->subDays(7)->format('Y-m-d'))
    ->groupBy('posts.id')
    ->first();

or select just the posts.id and get it in a new query

...
 ->select('posts.id', DB::raw('SUM(post_view.views) as views'))
...
//and then later
$post= Post::find($post_id);
Activity icon

Replied to Count Column In Hasmany

i think you will need a join, afaik this cannot be done with eager loading.

shooting from the hip, try this:

Post::join('post_view', 'post.id', '=', 'post_view.post_id')
    ->select('posts.*') // <- not sure about this one, so ids are not messed, play around
    ->orderByDesc('post_view.views')
    ->whereDate('post_view.date', '>=', Carbon::now()->subDays(7)->format('Y-m-d'))
    ->first();

Activity icon

Replied to Where Can I See The Websockets Routes?

@barley, i've never tried that, but i suggest you to start another thread here on the forum, someone might help you there

Activity icon

Replied to Storage::fake() & Reading File Contents

I usually refer to the non-api-documentation, here is the link to file path docs. I like the explanatory way of it and provided examples in comparison to the api documentation