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

SilenceBringer

SilenceBringer

Member Since 5 Years Ago

Experience Points
132,730
Total
Experience

2,270 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
661
Lessons
Completed
Best Reply Awards
110
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 27
132,730 XP
Nov
20
4 days ago
Activity icon

Awarded Best Reply on Why My Total Is Not Sum-ing Up

Hi @felicia00 your functions contains the problem. When you search by element id ($('#carval') and $('#val_perc')) you get exact element (because id must be unique on the page). But then you try to use it as a collection of elements. Of course it not works. If you have several element to sub by values - use classes instead of id

Or show us your html code, so we can advise something more detailed

Activity icon

Replied to Eloquent , How To Check If The Row Was Updated ?

Tsk-tsk, edited your answer =) You answered wrong first =)

Activity icon

Replied to Why My Total Is Not Sum-ing Up

@felicia00 not sure I understand you correctly, can you explain please? Also, please, consider marking response as the best answer if it solved your problem

Activity icon

Replied to Why My Total Is Not Sum-ing Up

Hi @felicia00 your functions contains the problem. When you search by element id ($('#carval') and $('#val_perc')) you get exact element (because id must be unique on the page). But then you try to use it as a collection of elements. Of course it not works. If you have several element to sub by values - use classes instead of id

Or show us your html code, so we can advise something more detailed

Activity icon

Replied to Eloquent , How To Check If The Row Was Updated ?

Hi @godzilaravel you need to use whereColumn for this reason

case 'initialized':
                        $eml = ($rule == 'or')
                            ? $eml->orwhereColumn(
                                'emls.created_at', 'emls.updated_at'
                            )
                            : $eml->whereColumn(
                                'emls.created_at', 'emls.updated_at'
                            );
                        break;
Nov
19
5 days ago
Activity icon

Replied to Laravel Hash And MD5 For Password.

Hi @iamkhan check 2 following links

Laravel Hashing for laravel

and

password_hash for vanilla php

both can use the same algorithms: bcrypt or argon. (bcrypt by default for both, I think)

Nov
16
1 week ago
Activity icon

Replied to How To Loop In Controller For Multiple Files

@webfuelcode as simple as

    foreach (['img1', 'img2'] as $img) {
        if($request->hasFile($img)){
            $filename = time() . '.' . $request->{$img}->getClientOriginalExtension();
            if($post->{$img}){
                Storage::disk('my_files')->delete('post_img/' . $post->{$img});
            }
            $request->{$img}->storeAs('post_img', $filename, 'my_files');
            
            $validated[$img] = $filename;
        }
    }
Nov
10
2 weeks ago
Activity icon

Replied to Add Element To An Array

Hi @r-dot really you are trying to do something strange...

UserAccountsModel::where($where_data)

this one returns query builder instance, not an array

'projects' => array(
                       "1234566"
                   )   

as far as projects is array (and looks like your project column is json in the database) in should be something like

               $projects => [
                   "1234566"
               ];
               $where = [
                   'role_id' => "5ba1ec5582539a8d5593e43d", 
                   'organization_id' => $organization_id,
               ];     
               $userAccountsModel = new UserAccountsModel();
               $pushProjectResult = $userAccountsModel->push_user_projects($projects, $where);
    public function push_user_projects($projects, $where) {
       return UserAccountsModel::where($where)->whereJsonContains('projects', $projects);
   } 
Nov
08
2 weeks ago
Activity icon

Awarded Best Reply on Constraining Relationships Problem !

@yagrasdemonde ok, try this

return Session::
            with('steps')
            ->whereHas('steps', function ($query) use ($eventDate) {
                $query
                    ->whereBetween('date', [$eventDate->subMonths(4)->format('Y-m-d'), $eventDate->format('Y-m-d')]);
            })
            ->whereDoesntHave('steps', function ($query) use ($eventDate) {
                $query->where('date', '>=', $eventDate);
            })
            ->get();
Activity icon

Awarded Best Reply on Tag Updating (comma-separated Tag) Issue In APP

@neeraj1005 I'm stupid =))

$tagIds = [];
if (request('tags') != '') {
            $tags = explode(',', request('tags'));
            // dd($tags);
            foreach ($tags as $tag_name) {
                $tag = Tag::updateOrCreate(['name' => $tag_name]);
                // dd($tag);
                $tagIds[] = $tag->id;
            }
        } 
                $post->tags()->sync($tagIds);

I created new variable and name it the same as you name yout tags from request

Activity icon

Replied to Eloquent Research Method

Hi @marcolino922 what the reason for using orWhere instead of where for searching?

Activity icon

Awarded Best Reply on Access Relation In Virtual Attribute And Performance

Hi @baserider try this

class SeminarController extends Controller
{
    public function show($id)
    {
        $seminarDates = SeminarDate::with('seminar')->where('seminar_id', $id)->get();

        echo '<h1>' . ($seminarDates->count() ? $seminarDates->first()->seminar->title : Seminar::find($id)->title) . '</h1>';
        foreach ($seminarDates as $seminarDate) {
            echo '<h4>'.$seminar->title.' (' . $seminarDate->type . ')</h4>';
            echo $seminarDate->price . '<hr>';
        }

        return '';
    }
}
Activity icon

Replied to Access Relation In Virtual Attribute And Performance

@baserider yes. with eager loads seminar for all the dates in 1 query

Activity icon

Replied to Tag Updating (comma-separated Tag) Issue In APP

@neeraj1005 I'm stupid =))

$tagIds = [];
if (request('tags') != '') {
            $tags = explode(',', request('tags'));
            // dd($tags);
            foreach ($tags as $tag_name) {
                $tag = Tag::updateOrCreate(['name' => $tag_name]);
                // dd($tag);
                $tagIds[] = $tag->id;
            }
        } 
                $post->tags()->sync($tagIds);

I created new variable and name it the same as you name yout tags from request

Activity icon

Replied to Tag Updating (comma-separated Tag) Issue In APP

@neeraj1005

$tags = [];
if (request('tags') != '') {
            $tags = explode(',', request('tags'));
            // dd($tags);
            foreach ($tags as $tag_name) {
                $tag = Tag::updateOrCreate(['name' => $tag_name]);
                // dd($tag);
                $tags[] = $tag->id;
            }
        } 
                $post->tags()->sync($tags);
Activity icon

Replied to Laravel Add Amount To The Next Parent In Loop

@whoami1509 what you mean under adding the amount? In your code example you just create new earnings with appropriate amounts. do you have some field with total amount, or?

Activity icon

Replied to CURL Error 6: Could Not Resolve Host:

@ddsameera can you show your code where you call the api?

Activity icon

Replied to Tag Updating (comma-separated Tag) Issue In APP

@neeraj1005

$tags = [];
if (request('tags') != '') {
            $tags = explode(',', request('tags'));
            // dd($tags);
            foreach ($tags as $tag_name) {
                $tag = Tag::updateOrCreate(['name' => $tag_name]);
                // dd($tag);
                $tags[] = $tag;
            }
        } 
                $post->tags()->sync($tags);
Activity icon

Replied to Access Relation In Virtual Attribute And Performance

Hi @baserider try this

class SeminarController extends Controller
{
    public function show($id)
    {
        $seminarDates = SeminarDate::with('seminar')->where('seminar_id', $id)->get();

        echo '<h1>' . ($seminarDates->count() ? $seminarDates->first()->seminar->title : Seminar::find($id)->title) . '</h1>';
        foreach ($seminarDates as $seminarDate) {
            echo '<h4>'.$seminar->title.' (' . $seminarDate->type . ')</h4>';
            echo $seminarDate->price . '<hr>';
        }

        return '';
    }
}
Activity icon

Replied to Tag Updating (comma-separated Tag) Issue In APP

Hi @neeraj1005 just replace this part

<input type="text" name="tags" class="form-control" 
   value="@foreach ($tags as $tag){{ $post->tags->contains($tag->id) ? $tag->name->implode(',') : '' }}@endforeach
                                            "
                                    />

with

<input type="text" name="tags" class="form-control" 
   value="{{ $post->tags->keyBy('name')->keys()->implode(', ') }} "
                                    />
Activity icon

Replied to What Is Wrong With My Edit Function/form?

@robinmvdoorn if you stay at the same page (form is not submitted) possible you have javascript code preventing default form submission? can you check your js console just in case?

Activity icon

Replied to Constraining Relationships Problem !

@yagrasdemonde ok, try this

return Session::
            with('steps')
            ->whereHas('steps', function ($query) use ($eventDate) {
                $query
                    ->whereBetween('date', [$eventDate->subMonths(4)->format('Y-m-d'), $eventDate->format('Y-m-d')]);
            })
            ->whereDoesntHave('steps', function ($query) use ($eventDate) {
                $query->where('date', '>=', $eventDate);
            })
            ->get();
Activity icon

Replied to What Is Wrong With My Edit Function/form?

Hi @robinmvdoorn do you see eny errors, or - what's going wrong? Do not perform update? Or?

At least I can see this

return redirect(route('.books'));

Route name .books looks wrong

Activity icon

Replied to Constraining Relationships Problem !

Hi @yagrasdemonde I think it should be something like:

return Session::
            with('steps')
            ->whereHas('steps', function ($query) use ($eventDate) {
                $query
                    ->whereBetween('date', [$eventDate->subMonths(4)->format('Y-m-d'), $eventDate->format('Y-m-d')]);
            })
            ->get();
Activity icon

Replied to Laravel Add Amount To The Next Parent In Loop

@whoami1509 see this question not the first time, but it's still not clear for me. But - ok, let's try

$userId = 5; //jade

//call function with $user as argument
self::insertEarnings($userId);
use \Illuminate\Support\Arr;

protected $rankAmount = [
    'Junior' => 100,
    'Premium' => 150,
    'Advanced' => 200,
    'Senior' => 250,
];

private function insertEarnings($userId) {
    $user = User::get($userId);

    if ($user) {
        if (Arr::has($this->rankAmount, $user->rank)) {
            $earnings = new Earnings;
            $earnings->user_id = $user->id;
            $earnings->amount = Arr::get($this->rankAmount, $user->rank);
            $earnings->save();
        }

        if ($user->parent_id) {
            $this->insertEarnings($user->parent_id);
        }
    }
}
Activity icon

Awarded Best Reply on Testing Belongs To Relationship

@ivan2nn try to remove this

       $this->withoutExceptionHandling();
Activity icon

Awarded Best Reply on 'whereTime' Weird Behavior

@thebigk everythink works correctly

whereDate('subscription_valid_till', '>=', today())

// in result

subscription_valid_till: "2020-11-15 00:00:00",

date in result is 2020-11-15, it's less then 2020-11-09

whereTime('next_message_at', '<=', now())

// result 

 next_message_at: "2020-11-09 09:02:00"

so, the time pasrt of result is 09:02:00, and it's less then 12:06:39 in now

Your conditions looks wrong, but query works as expected. Tell us what you try to achieve and we will try to help you

Activity icon

Replied to 'whereTime' Weird Behavior

@thebigk everythink works correctly

whereDate('subscription_valid_till', '>=', today())

// in result

subscription_valid_till: "2020-11-15 00:00:00",

date in result is 2020-11-15, it's less then 2020-11-09

whereTime('next_message_at', '<=', now())

// result 

 next_message_at: "2020-11-09 09:02:00"

so, the time pasrt of result is 09:02:00, and it's less then 12:06:39 in now

Your conditions looks wrong, but query works as expected. Tell us what you try to achieve and we will try to help you

Activity icon

Awarded Best Reply on How To Get Last Id Or Row From Table Through ID

Hi @coder72 use mzx

$maxDealerId=Product::max('dealer_id');
Activity icon

Replied to Testing Belongs To Relationship

@ivan2nn try to remove this

       $this->withoutExceptionHandling();
Activity icon

Replied to How To Get Last Id Or Row From Table Through ID

Hi @coder72 use mzx

$maxDealerId=Product::max('dealer_id');
Activity icon

Replied to Testing Belongs To Relationship

@ivan2nn don't see the mistake at first looks. Please, can you dump the data in 2 places

   public function a_project_requires_a_user()
   {
       $this->withoutExceptionHandling();

       $attributes = Project::factory()->raw(['user_id' => null]);
       dump($attributes);
       $this->post('/projects', $attributes)->assertSessionHasErrors('user_id');
   }

and second one

public function store() 
    {
        $attributes = request()->validate([
            'personal_code' => 'required',
            'code'        => 'required',
            'description'   => 'required',
            'user_id'       => 'required'
        ]);

    dd($attributes);
    Project::create($attributes);

    return redirect('/projects');
}
Activity icon

Awarded Best Reply on Delete Tags In Polymorphic Many To Many

@mehrdad70 I think you can call sync with empty array do detach all existing tags, like

$article->tags()->sync([]);

Or you can do it at database layer, and specify onDelete('cascade') for tag_id in taggables table

Activity icon

Replied to Delete Tags In Polymorphic Many To Many

@mehrdad70 I think you can call sync with empty array do detach all existing tags, like

$article->tags()->sync([]);

Or you can do it at database layer, and specify onDelete('cascade') for tag_id in taggables table

Activity icon

Replied to Laravel 7 Auth

@beingsk try php artisan ui react --auth and check if it suits your needs

Nov
07
2 weeks ago
Activity icon

Replied to How To Generate Random Coordinates Around Given Coordinates With Faker

@princeoo7 anyway, just to check, try to visa versa it. if it still not works, try something like:

$lang = 33.7490;
$long = -84.3880;

"langtitude" => $faker->latitude(
    $min = ($lang * 10000 - rand(0, 50)) / 10000,
    $max = ($lang * 10000 + rand(0, 50)) / 10000
),
"longitute" => $faker->longitude(
    $min = ($long * 10000 - rand(0, 50)) / 10000,
    $max = ($long * 10000 + rand(0, 50)) / 10000
),
Activity icon

Replied to How To Push In Ajax?

@irankhosravi so, check where and how you get this $data. I think, it shouldn't be null to works correctly =) show us the code when you get the data from ajax call

Activity icon

Awarded Best Reply on How You Sync OneToMany Relationship

Hi @newbie360 if you don't have direct relations to id in product_keywords table, it will be much simplier to remove all existing keywords and store new ones

        DB::beginTransaction();
        try{
            $product->productKeywords()->delete();

            $keywords = array_map(function ($keyword) {
                return ['keyword' => $keyword];
            }, $keywords);

            $product->productKeywords()->createMany($keywords);

            DB::commit();
        } catch (\Exception $e) {
            DB::rollBack();
            return back()->withErrors(['transaction_error' => $e->getMessage()]);
        }
        // End Transaction
Activity icon

Replied to How To Generate Random Coordinates Around Given Coordinates With Faker

@princeoo7 possible you set lat and lng visa versa? Because this

$lang = -84.3880;
$long = 33.7490;

points to the antarctica

Activity icon

Replied to How To Generate Random Coordinates Around Given Coordinates With Faker

@princeoo7 if you want point near your real coordinates, you need to change coordinates just about 0.001 or less. So, I can suggest something like

$lang = 33.7490;
$long = -84.3880;

"langtitude" => $faker->latitude($min = ($lang - (rand(0,20) / 1000)), $max = ($lang + (rand(0,20) / 1000))),
"longitute" => $faker->longitude($min = ($long - (rand(0,20) / 1000)), $max = ($long + (rand(0,20) / 1000))),
Activity icon

Replied to How To Do Filter Search In Laravel ?

@maaz please show us your code

Activity icon

Replied to How To Push In Ajax?

@irankhosravi just replace dd with var_dump to see data structure

function save($data)
{
    var_dump($data);exit;
Activity icon

Replied to How To Push In Ajax?

@michaloravec I think he tries to append state and city names to state_id and city_id in form data

Activity icon

Replied to How To Push In Ajax?

Hi @irankhosravi here

 data.push({'name':'state_name', 'value':state_name});

you specify the array, so, your $data array in php have something like:

['name' => 'state_name', 'value' => 'stateValue']

of course, you can't access it as

$data['state_name']

just dump the $data:

function save($data)
{
    dd($data);

to see the format

Activity icon

Awarded Best Reply on Uncaught SyntaxError: Unexpected Token <

Hi @marcolino922 you have 2 places with php inserts

url:"{{ url('save-like') }}",

//and

_token:"{{ csrf_token() }}",

first one you can pass as data-attribute, like

<a href="#" data-url="{{ url('save-like') }}" id="saveLike">save like</a>

and then access it in js

var url=$(this).data('url');

second one can be solved as described in documentation

Activity icon

Replied to Uncaught SyntaxError: Unexpected Token <

Hi @marcolino922 you have 2 places with php inserts

url:"{{ url('save-like') }}",

//and

_token:"{{ csrf_token() }}",

first one you can pass as data-attribute, like

<a href="#" data-url="{{ url('save-like') }}" id="saveLike">save like</a>

and then access it in js

var url=$(this).data('url');

second one can be solved as described in documentation

Activity icon

Replied to How You Sync OneToMany Relationship

@newbie360 no problems id will keep growing. primary id is big int by default in laravel, so, you can use it for a very long time =)

about the order: keywords should come in the same order as you input it. so, what the problem here?