Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

s4muel

s4muel

Member Since 3 Years Ago

Experience Points
92,450
Total
Experience

2,550 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
502
Lessons
Completed
Best Reply Awards
71
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 19
92,450 XP
Nov
22
2 days ago
Activity icon

Awarded Best Reply on Auto Format All Files Using Phpcs

are all of your controllers in one directory? if so,

phpcs --standard=PSR2 app/Http/Controllers

where app/Http/Controllers is path to your controllers

or if you are on linux, combining the find tool with execution of the phpcs command could be a way, possibly:

find  . -name "*Controller.php" -exec phpcs --standard=PSR2 {} \; 

run in your project root

Nov
19
5 days ago
Activity icon

Replied to Get Results Where Smallest Child Value Is X

ok then, my last shot, i promise;)

$seminars = Seminar::whereHas('seminarData', function ($query) {
        $query->whereIn('id', SeminarData::select('id')
            ->where(function ($query) {
                $query->selectRaw(DB::raw('DATE("date")'))
                    ->from('seminar_data')
                    ->whereColumn('seminar_id', 'seminars.id')
                    ->orderBy('date')
                    ->limit(1);
            }, now()->toDateString())
        );
    })->get();

playground

Nov
18
6 days ago
Activity icon

Replied to Get Results Where Smallest Child Value Is X

really? sorry then, i give up. i hope someone else will help you

Activity icon

Replied to Git & Laravel: How To Fix The Problem Of Merge Conflict (GitLab)?

you need to resolve all local conflicts first, then add and commit the changes to public/js/app.js (and other conflicts if you have some)

or, if you tried a merge before but didn't complete it, you can revert the merge git reset --merge and start over.

the above command explanation, from documentation:

Resets the index and updates the files in the working tree that are different between and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between and the index has unstaged changes, reset is aborted.

Nov
17
1 week ago
Activity icon

Replied to Get Results Where Smallest Child Value Is X

@basvandertogt oh, i see, i was too excited to see that working 🙈,

of course you need to filter (using the having condition) by a date, not a datetime. here is the updated playground and i will update my answer above as well. try if that works for you.

the reason why it worked for me, is because my test data had the same "datetime" as now() since it was created with now()

Nov
16
1 week ago
Activity icon

Replied to Get Results Where Smallest Child Value Is X

@basvandertogt yeah, i realized that as soon as i posted it. and both of you reminded me well also;)

can't think of anything better (without the raw part, i wasn't able to handle it with whereDate(), which would be nice), but this might help? a bit? perhaps?

$seminars = App\Seminar::whereHas('seminarData', function ($query) {
    $query->whereIn('id', App\SeminarData::select('id')
        ->groupBy('seminar_id')
        ->havingRaw('MIN("date")')
        ->having(DB::raw('DATE("date")'), now()->toDateString())
        //or ->havingRaw('DATE("date") = ?', [now()->toDateString()])
    );
})->get();

here is the playground

Nov
13
1 week ago
Activity icon

Replied to Get Results Where Smallest Child Value Is X

if you have the relationships set, you can use:

$seminars = App\Seminar::whereHas('seminar_data', function ($query) {
    $query->whereDate('date', Carbon::today()));
})->get();

edit: ah, sorry i missed the point of smallest date

Activity icon

Replied to PHP Artisan Doesn't Work After Updating Composer

i would try removing the vendor folder completely along with the composer.lock file and running composer install again, if that is an option

Activity icon

Replied to PHP Artisan Doesn't Work After Updating Composer

is your laravel installer up to date? also try running composer dump-autoload

Nov
11
1 week ago
Activity icon

Replied to How To Pass Variable From Variables From One Function To Another In View Blade

you set them up inside a function, so they are not available out of the scope (in the disabledays() function. set them again from the element value before use

    let weekendInclusives = parseInt($("#weekendinclusive").val());
    let holidayInclusives = parseInt($("#holidayinclusive").val());

    if (weekendInclusives == 0 && holidayInclusives == 0) {
      dateOpts.beforeShowDay = noWeekendsAndHolidays;
    } else if (weekendInclusives == 0 && holidayInclusives == 1) {
      dateOpts.beforeShowDay = noHolidays;
    } else if (weekendInclusives == 1 && holidayInclusives == 0) {
      dateOpts.beforeShowDay = $.datepicker.noWeekends;
    }
Nov
10
2 weeks ago
Activity icon

Replied to Fatal Error: Allowed Memory Size Of 1610612736 Bytes Exhausted (tried To Allocate 4096 Bytes) In Phar:///usr/local/Cellar/composer/1.10.13/bin/composer/src/Composer/DependencyResolver/Solver.php On Line 223

as a quick fix you can run

COMPOSER_MEMORY_LIMIT=-1 composer update

replace the update to your liking

edit: oh, and upgrade to composer 2 if you can, as guys suggest 👇

Activity icon

Replied to Getting Undefined In Route After Creating Record.

@ajsmith_codes omit this part completely

$order = Order::where('active', 1)
->orderBy('created_at', 'asc')
->first();
Activity icon

Replied to Getting Undefined In Route After Creating Record.

you are probably getting different order, aren't you?

//...
$order->payment_type = $request->payment_type;

$order->save();

//why do you get order here? this probably gets the oldest active order, dont you want to use the current one?
$order = Order::where('active', 1)
->orderBy('created_at', 'asc')
->first();
Activity icon

Replied to Getting Undefined In Route After Creating Record.

how do you obtain a slug? custom slug() method in Order model?

if you don't have and accessor (getSlugAttribute()) defined in the model, you need to access it by calling a method name($order->slug()). try:

return redirect(route($currentUserRole . '.salesorders.show', $order->slug()));
Activity icon

Awarded Best Reply on Problem Displaying Barcode Using Milon/barcode With DomPDF

give this a shot. i replaced :: with :

<img src="data:image/png;base64,{{ DNS1D::getBarcodePNG($data->code_product,'C39') }}" height="60" width="180" /><br />
Activity icon

Replied to Problem Displaying Barcode Using Milon/barcode With DomPDF

give this a shot. i replaced :: with :

<img src="data:image/png;base64,{{ DNS1D::getBarcodePNG($data->code_product,'C39') }}" height="60" width="180" /><br />
Nov
09
2 weeks ago
Activity icon

Replied to Chart.js Passing Data

@randy_johnson great! and i hope, at least, you learned about the @json directive today;)

Activity icon

Replied to Chart.js Passing Data

what is in your $data variable? does it have an item with index 0 (either explicit or "by default" from non-associative array)?

and there is a blade helper for json_encode, so you can use var data = @json($data);instead.

Activity icon

Replied to Calculate Price Within Model Which Depends On Data From Another Model

@baserider, please, share with us, it might help others with similar problem

Nov
05
2 weeks ago
Activity icon

Awarded Best Reply on Uncaught SyntaxError: '' String Literal Contains An Unescaped Line Break

have you tried this?

echo '<li onclick="updateBasket(' . $i . ', value[\'basketID\'])">' . $i . '</li>'; 

i suggest at least switching from php to javascript when using the for loop

var tr = '<tr>\n' + 
//... +
'<ul>';

var i;
for (i = 1; i < 31; i++) {
  tr += '<li onclick="updateBasket(' + i + ', ' + value['basketID'] + ')">' + i + '</li>';
}
tr += '</ul>';

at least make this work and then try a find a totally different approach

Activity icon

Replied to Uncaught SyntaxError: '' String Literal Contains An Unescaped Line Break

have you tried this?

echo '<li onclick="updateBasket(' . $i . ', value[\'basketID\'])">' . $i . '</li>'; 

i suggest at least switching from php to javascript when using the for loop

var tr = '<tr>\n' + 
//... +
'<ul>';

var i;
for (i = 1; i < 31; i++) {
  tr += '<li onclick="updateBasket(' + i + ', ' + value['basketID'] + ')">' + i + '</li>';
}
tr += '</ul>';

at least make this work and then try a find a totally different approach

Activity icon

Replied to Uncaught SyntaxError: '' String Literal Contains An Unescaped Line Break

you mix up php and javascript here:

echo '<li onclick="updateBasket('.$i.','+value['basketID'].')"><?= $i ?></li>';

you are still in php context, when using <?= $i ?> the value['basketId'] has to be evaluated in JS? dont you have that basketId variable present in php?

//this just echoes out `value['basketId']`, but i am not sure it will work as you expect
echo '<li onclick="updateBasket(' . $i . ', value[\'basketID\'])">' . $i . '</li>'; 

//this should work when you have the `$basketId` in php
echo '<li onclick="updateBasket(' . $i . ', ' . $basketId . ')">' . $i . '</li>';

but i strongly suggest to refactor all of that code, you are in JS context printing HTML using PHP that prints HTML and JS 🤯

Nov
04
2 weeks ago
Activity icon

Replied to Except Helper Assistance.

@madsynn glad to help. and btw i like the marked best answer;) 👍

Nov
03
3 weeks ago
Activity icon

Replied to Can't Access My Home Page Because Of This Error

show us your master.blade.php.

do you access it like $categoryid->breaking_news_category_id? if so, do you pass $categoryid to the view?

Activity icon

Replied to Except Helper Assistance.

does this work?

$data = Product::whereHas('product_categories', function ($query) use ($request) {
    $query->where('id', $request->category);
})->whereNotIn('type', ['services', 'code'])->get();
Oct
30
3 weeks ago
Activity icon

Replied to Auto Format All Files Using Phpcs

are all of your controllers in one directory? if so,

phpcs --standard=PSR2 app/Http/Controllers

where app/Http/Controllers is path to your controllers

or if you are on linux, combining the find tool with execution of the phpcs command could be a way, possibly:

find  . -name "*Controller.php" -exec phpcs --standard=PSR2 {} \; 

run in your project root

Oct
28
4 weeks ago
Activity icon

Replied to How To Save QR Code From Google API Into Storage

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str; //optional
//...
$contents = file_get_contents('https://chart.googleapis.com/chart?chs=400x400&cht=qr&chl=My_Data');

$filename = 'your_unique_filename.png'; //e.g. user id, or a hash, or random string, or uuid
//$filename = (string) Str::uuid() . '.png';

Storage::put($filename, $contents);
Activity icon

Awarded Best Reply on Laravel Sessions Database Table Filling Up With User_agent ELB-HealthChecker/2.0

create a new middleware that sets the session driver to an array if user agent string matches the healthcheck. put (register) it before StartSession middleware in Kernel.php

middleware could look something like this:

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Config;

class NoSessionForHealthCheck
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (request()->header('User-Agent') && strpos(request()->header('User-Agent'), 'ELB-HealthChecker') !== false) {
            Config::set('session.driver', 'array');
        }

        return $next($request);
    }
}
Oct
27
4 weeks ago
Activity icon

Replied to Laravel Sessions Database Table Filling Up With User_agent ELB-HealthChecker/2.0

create a new middleware that sets the session driver to an array if user agent string matches the healthcheck. put (register) it before StartSession middleware in Kernel.php

middleware could look something like this:

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Config;

class NoSessionForHealthCheck
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (request()->header('User-Agent') && strpos(request()->header('User-Agent'), 'ELB-HealthChecker') !== false) {
            Config::set('session.driver', 'array');
        }

        return $next($request);
    }
}
Oct
26
4 weeks ago
Activity icon

Awarded Best Reply on Create Factory Using Faker, Where One Field Depends On The Value Of Another.

public function definition()
    {
        $users = User::all()->pluck('id')->toArray();
        $availability = $this->faker->numberBetween($min=1, $max=50);
        $quantity = $this->faker->numberBetween($min=$availability, $max = 50);

        return [
            'user_id' =>$this->faker->randomElement($this->users),
            'title' => $this->faker->text,
            'detail' => $this->faker->text,
            'features' => $this->faker->text,
            'availability' => $availability,
            'quantity' => $quantity,
            'is_unlimited' => $this->faker->numberBetween($min=0, $max=1),
            'is_new' => $this->faker->numberBetween($min=0, $max=1),
            'weight' => $this->faker->numberBetween($min=0, $max=1),
            'status' => 'active',
            'discount' => $this->faker->numberBetween($min=0, $max=10),
            'price' => $this->faker->numberBetween($min=10, $max=100)
        ];
    }
Activity icon

Replied to Create Factory Using Faker, Where One Field Depends On The Value Of Another.

public function definition()
    {
        $users = User::all()->pluck('id')->toArray();
        $availability = $this->faker->numberBetween($min=1, $max=50);
        $quantity = $this->faker->numberBetween($min=$availability, $max = 50);

        return [
            'user_id' =>$this->faker->randomElement($this->users),
            'title' => $this->faker->text,
            'detail' => $this->faker->text,
            'features' => $this->faker->text,
            'availability' => $availability,
            'quantity' => $quantity,
            'is_unlimited' => $this->faker->numberBetween($min=0, $max=1),
            'is_new' => $this->faker->numberBetween($min=0, $max=1),
            'weight' => $this->faker->numberBetween($min=0, $max=1),
            'status' => 'active',
            'discount' => $this->faker->numberBetween($min=0, $max=10),
            'price' => $this->faker->numberBetween($min=10, $max=100)
        ];
    }
Oct
22
1 month ago
Activity icon

Replied to Child-Parent Relationship On An Index | Update Won't Cascade

@tom-shelby , from your post, the error was:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`db`.`folders`, CONSTRAINT `folders_parent_folder_number_foreign` FOREIGN KEY (`parent_folder_number`) REFERENCES `folders` (`number`) ON DELETE SET NULL ON UPDATE CASCADE) (SQL: update `folders` set `number` = 1 where `id` = 9)

it says, that a constraint failed for a column number, but up in your migration code, you posted ->references('folder_number')->on('folders');

my question was, what is your foreign key definition for that column number in your migrations?

Oct
20
1 month ago
Activity icon

Replied to How Important And Necessary Is UUID At Laravel?

IMHO there is no difference in this case. user cant login or masquarade to another users account or bypass guards just by knowing and spoiling the users id. provided that there is no mistake in your custom authentication/authorization logic.

Activity icon

Replied to Exception\NotFoundHttpException Error ?

is that the whole stack trace? i am not sure about the NULL parameter in handleMatchedRoute(Object(Illuminate\Http\Request), NULL) does the app work fine, right? just that error occurs? with every request or randomly?

what does php artisan route:list say? any possible duplicated routes? or a controller redirecting to a route with different http method?

Activity icon

Replied to Child-Parent Relationship On An Index | Update Won't Cascade

hm, does this (onDelete, onUpdate) even work, when there is no constraint ?

$table->bigInteger('folder_number')
          ->unsigned()
          ->index()
          ->onDelete('SET NULL')
          ->onUpdate('CASCADE');

anyway, from the error, there is:

...update `folders` set `number` = 1 where `id` = 9)...

how does the foriegn key constraint look like for a number column?

Activity icon

Replied to How Important And Necessary Is UUID At Laravel?

well this (id vs uuid) is not larvel specific. it highly depends case by case. most simple advantage, for example, is if you are afraid that a user can get all items (scrape) just by iterating id in the url, use uuid. it is not just that, of course. pros/cons depends too. you can get the id before it is even stored to database (kind of), but the relationships in db and indices are bit more messy, takes more place, but for a stadard-size application, i would't worry.

so if you do not expose the id in any way, i would simple not use the uuid and pick plain int ids

Oct
16
1 month ago
Activity icon

Awarded Best Reply on Set A Foreign Key To Nullable In Laravel 8

if you use migrations, create new one and change the column via new migration

...
Schema::table('signs', function (Blueprint $table) {
    //use your current column type instead of unsignedBigInteger, if needed
    $table->unsignedBigInteger('po_id')->nullable()->change();
});
...

if not, update the column manually in a database client of your choice

Activity icon

Replied to Set A Foreign Key To Nullable In Laravel 8

if you use migrations, create new one and change the column via new migration

...
Schema::table('signs', function (Blueprint $table) {
    //use your current column type instead of unsignedBigInteger, if needed
    $table->unsignedBigInteger('po_id')->nullable()->change();
});
...

if not, update the column manually in a database client of your choice

Oct
15
1 month ago
Activity icon

Awarded Best Reply on Time Logic To Code

i suggest using this library: https://github.com/spatie/period

there is a $period->overlapsWith(Period $period): bool (and other period magic useful stuff)

it's not directly in eloquent, but i suppose you won't have any problems using it "outsude" to check if a period is clear

Activity icon

Replied to Time Logic To Code

i suggest using this library: https://github.com/spatie/period

there is a $period->overlapsWith(Period $period): bool (and other period magic useful stuff)

it's not directly in eloquent, but i suppose you won't have any problems using it "outsude" to check if a period is clear

Oct
13
1 month ago
Activity icon

Replied to Spatie Role And Permission

does php artisan permission:show show something reasonable?

Oct
12
1 month ago
Activity icon

Awarded Best Reply on [8.x]BUG?

yep, it currently (and unfortunately) only works on table named migrations https://github.com/laravel/framework/pull/34746

Activity icon

Replied to [8.x]BUG?

yep, it currently (and unfortunately) only works on table named migrations https://github.com/laravel/framework/pull/34746

Oct
09
1 month ago
Activity icon

Awarded Best Reply on Laravel 7 With Apache2 - Virtualhost Config Not Redirect To Public Folder

oh, i see. if you want to access the page on localhost:8080, you need to specify that in the <VirtualHost HERE> directive. because, currently like that, it only "listens" on 127.0.1.2

either add localhost:8080, like this <VirtualHost 127.0.1.2:8080 localhost:8080> (i suppose), or use a wildcard

<VirtualHost *:8080>
...
Activity icon

Replied to Laravel 7 With Apache2 - Virtualhost Config Not Redirect To Public Folder

oh, i see. if you want to access the page on localhost:8080, you need to specify that in the <VirtualHost HERE> directive. because, currently like that, it only "listens" on 127.0.1.2

either add localhost:8080, like this <VirtualHost 127.0.1.2:8080 localhost:8080> (i suppose), or use a wildcard

<VirtualHost *:8080>
...
Activity icon

Replied to Laravel 7 With Apache2 - Virtualhost Config Not Redirect To Public Folder

if you execute these two command, what does the second output?

source /etc/apache2/envvars
/usr/sbin/apache2 -S
Activity icon

Replied to Laravel 7 With Apache2 - Virtualhost Config Not Redirect To Public Folder

.htaccess like that is not needed. everything should be handled by the vhost configuration. the DocumentRoot directive says where are the files served from, so it should work, have you reloaded/restarted apache service after these changes?

Oct
08
1 month ago
Activity icon

Awarded Best Reply on Http::withToken Get Total Time Of Request

getTransferTime() is public method (getter), try that.

$response->transferStats->getTransferTime()

Activity icon

Replied to Http::withToken Get Total Time Of Request

getTransferTime() is public method (getter), try that.

$response->transferStats->getTransferTime()

Oct
05
1 month ago
Activity icon

Awarded Best Reply on Returns All Product Data By Category In Json Format

this is as far as i can get:

$products = Product::all();

$grouped = $products->mapToGroups(function ($item, $key) {
    return [$item['category_name'] => $item];
})->map(function ($item, $key) {
    $products = $item->map(function($item, $key) {
        return $item->only('name', 'price');
    });
    return ['product' => $products];
})->map(function ($item, $key) {
    return ['category' => $key, 'product' => $item['product']];
})->values();

dump($grouped);
dump($grouped->toJson(JSON_PRETTY_PRINT));

plus this

return response()->json([
                'result' => 'true',
                'data' => $grouped,
            ], 200);

here is the playground: https://laravelplayground.com/#/snippets/79375205-98e9-40b3-bf4f-9bfb455a35de