Sti3bas

Member Since 2 Years Ago

Experience Points
194,070
Total
Experience

930 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
1109
Lessons
Completed
Best Reply Awards
139
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 39
194,070 XP
Jan
18
1 day ago
Activity icon

Replied to Prevent None Verified User From Logging In

@jove one option would be to override authenticated method:

 protected function authenticated(Request $request, $user)
 {
    if(!$user->isVerified) {
       Auth::logout();

       session()->flash('status', 'Please verify your account!');

       return redirect(route('login'));
    }
 }

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php#L120

Jan
17
2 days ago
Activity icon

Awarded Best Reply on How To Change Or Override The Login Query

@minafaragamin if you only need to specify additional where or whereIn condition, you can override credential method in LoginController:

protected function credentials(Request $request)
{
   return array_merge([
      'is_admin' => true
   ], $request->only($this->username(), 'password'));
}

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php#L92

Otherwise, you would probably need to extend EloquentUserProvider and add the logic you want.

https://github.com/illuminate/auth/blob/master/EloquentUserProvider.php

Activity icon

Awarded Best Reply on Check Field In Addition To Password Before Sending Password Email

@pbsmith same way as login. Add this to your ForgotPasswordController controller:


protected function credentials(Request $request)
{
   return array_merge($request->only('email'), [
      'organization' => config('meeting-settings.organization')
   ]);
}

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Auth/SendsPasswordResetEmails.php#L59

Activity icon

Replied to Check Field In Addition To Password Before Sending Password Email

@pbsmith same way as login. Add this to your ForgotPasswordController controller:


protected function credentials(Request $request)
{
   return array_merge($request->only('email'), [
      'organization' => config('meeting-settings.organization')
   ]);
}

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Auth/SendsPasswordResetEmails.php#L59

Activity icon

Replied to Phone Formatting Issue

@artisticre this is a great package for formatting phone numbers: https://github.com/Propaganistas/Laravel-Phone#formatting

Activity icon

Awarded Best Reply on How To Override Carbon

@stefr you're overriding it correctly.

>>> $date = \App\CarbonOverride::parse('2019-12-12');
=> App\CarbonOverride @1576108800 {#3006
     date: 2019-12-12 00:00:00.0 UTC (+00:00),
   }
>>> $date->test = '2000-01-06 00:00:00';
"test" // <- this was dumped 
"2000-01-06 00:00:00" // <- this was dumped 
=> "2000-01-06 00:00:00"
>>>

But __set will not be called, because you're trying to override existing date property.

__set() is run when writing data to inaccessible (protected or private) or non-existing properties.

https://www.php.net/manual/en/language.oop5.overloading.php#object.set

Activity icon

Replied to How To Override Carbon

@stefr you're overriding it correctly.

>>> $date = \App\CarbonOverride::parse('2019-12-12');
=> App\CarbonOverride @1576108800 {#3006
     date: 2019-12-12 00:00:00.0 UTC (+00:00),
   }
>>> $date->test = '2000-01-06 00:00:00';
"test" // <- this was dumped 
"2000-01-06 00:00:00" // <- this was dumped 
=> "2000-01-06 00:00:00"
>>>

But __set will not be called, because you're trying to override existing date property.

__set() is run when writing data to inaccessible (protected or private) or non-existing properties.

https://www.php.net/manual/en/language.oop5.overloading.php#object.set

Activity icon

Awarded Best Reply on Variable Cannot Be Found In Parent Controller Php

@randy_johnson remove $ sign:

   $this->table = "products";       
   $this->p = "user/products";
Jan
16
3 days ago
Activity icon

Awarded Best Reply on How To Style Role View To Three Columns

@noblemfd what about:

<div class="col-xs-12">
   <strong>Permission:</strong>

   <div class="row">
      @foreach($permission as $value)
         <div class="form-group col-md-4">
            <label>
               {{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
               {{ $value->name }}
            </label>
         </div>
      @endforeach
   </div>
</div>
Activity icon

Replied to Variable Cannot Be Found In Parent Controller Php

@randy_johnson remove $ sign:

   $this->table = "products";       
   $this->p = "user/products";
Activity icon

Replied to Logic Eloquent

@heimdall

$dogs = Dog::with('images')->take(10)->get();
Activity icon

Replied to Logic Eloquent

@heimdall update your relationship to $this->hasMany(Image::class, 'id_dog');

Activity icon

Replied to Logic Eloquent

@heimdall what does it show if you add this to the controller?:

$dogs= Dog::orderBy('id','DESC')->with('images')->take(10)->get();

dd($dogs);
Activity icon

Replied to Logic Eloquent

@heimdall what are you storing in $data variable? Can you show what you're passing from the controller?

Activity icon

Replied to Logic Eloquent

@heimdall I was asking for a view, not for the stack trace.

Activity icon

Awarded Best Reply on Cannot Pass Variable To Mailable

@dan3460

return (new MailMessage)->markdown('mail.users.passwordReset', ['token' => $this->token]);

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Notifications/Messages/MailMessage.php#L121

Activity icon

Replied to Logic Eloquent

@heimdall can you post your full view?

Activity icon

Replied to Cannot Pass Variable To Mailable

@dan3460 yes, public properties are available in view when you're using Mailable classes: https://laravel.com/docs/6.x/mail#view-data

Activity icon

Replied to Cannot Pass Variable To Mailable

@dan3460

return (new MailMessage)->markdown('mail.users.passwordReset', ['token' => $this->token]);

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Notifications/Messages/MailMessage.php#L121

Activity icon

Replied to Logic Eloquent

@heimdall which line of the code throws an error?

Activity icon

Awarded Best Reply on Can Eloquent Accept Unix Time For Date Fields?

Migration:

Schema::create('tests', function (Blueprint $table) {
   //...
   $table->timestamp('test_date')->nullable();
});

Model:

class Test extends Model
{
   //...
   protected $dates = [
       'test_date'
   ];
}

Tinker:

>>> $model = \App\Test::first();
=> App\Test {#3042
      //...
      test_date: null,
   }
>>> $model->test_date = 1579183788;
=> 1579183788
>>> $model->save();
=> true
>>> $model->fresh();
=> App\Test {#3027
      //...
      test_date: "2020-01-16 14:09:48",
   }
>>>
Activity icon

Replied to Logic Eloquent

@heimdall try this:

@foreach($dog->images as $image)
   <img src="/images/{{ $image->image }}" alt="{{ $dog->name }}"  />
@endforeach
Activity icon

Replied to Use App\User;

@afoysal post your full HomeController controller.

Activity icon

Replied to Logic Eloquent

@heimdall well, from the code above it seems like you have Image model and images relationship in your Dog model. How does your images table looks like?

Activity icon

Replied to Logic Eloquent

@heimdall replace $dog->image with $dog->images.

Activity icon

Replied to How To Change Or Override The Login Query

@minafaragamin if you only need to specify additional where or whereIn condition, you can override credential method in LoginController:

protected function credentials(Request $request)
{
   return array_merge([
      'is_admin' => true
   ], $request->only($this->username(), 'password'));
}

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php#L92

Otherwise, you would probably need to extend EloquentUserProvider and add the logic you want.

https://github.com/illuminate/auth/blob/master/EloquentUserProvider.php

Activity icon

Replied to Logic Eloquent

@heimdall I don't know how you're storing your images, but it should be similar to this:

@foreach($dog->images as $image)
   <img src="/images/{{ $image->url }}" alt="{{ $dog->name }}"  />
@endforeach
Activity icon

Replied to Can Eloquent Accept Unix Time For Date Fields?

Migration:

Schema::create('tests', function (Blueprint $table) {
   //...
   $table->timestamp('test_date')->nullable();
});

Model:

class Test extends Model
{
   //...
   protected $dates = [
       'test_date'
   ];
}

Tinker:

>>> $model = \App\Test::first();
=> App\Test {#3042
      //...
      test_date: null,
   }
>>> $model->test_date = 1579183788;
=> 1579183788
>>> $model->save();
=> true
>>> $model->fresh();
=> App\Test {#3027
      //...
      test_date: "2020-01-16 14:09:48",
   }
>>>
Activity icon

Replied to Logic Eloquent

Add hasMany relationship to your Dog model:

class Dog extends Model
{
    public function photos()
    {
        return $this->hasMany(Photo::class);
    }
}

Then you will be able to access it with $dog->photos.

https://laravel.com/docs/6.x/eloquent-relationships#one-to-many

Note: if you're loading multiple dogs from the database, make sure you add ->with('photos') to eager load photos and avoid n+1 problem.

https://laravel.com/docs/6.x/eloquent-relationships#eager-loading

Activity icon

Replied to Calling An API From A Controller

@gouseferoz take a look at Guzzle: http://docs.guzzlephp.org/en/stable/

Also, if you want a simple Guzzle wrapper, take a look at: https://github.com/kitetail/zttp

Activity icon

Replied to Testing Login Functionality

@lavina what if you remove $this->withoutMiddleware();?

Activity icon

Replied to Testing Login Functionality

@lavina make sure that APP_ENV (phpunit.xml) env variable is set to testing, if you get 419 error in your tests. You can also check the environment by adding dd(app()->env); to your test.

Activity icon

Replied to Testing Login Functionality

@lavina add $this->withoutExceptionHandling(); at the top of the test to see the exact error.

Activity icon

Replied to SQLSTATE[HY000]: General Error

@aeonfox can you show your users table migration? Seems like id field doesn't set to auto-increment.

Activity icon

Awarded Best Reply on How To Change PDF Name

@shing_shing do you tried download atribute?

<a href="/path/to/pdf.pdf" download="your-custom-name">Download</a>

https://www.w3schools.com/tags/att_a_download.asp

Note: not supported in Internet Explorer.

Jan
15
4 days ago
Activity icon

Replied to Algolia

@mehmetanbaki haven't used any of these.

Activity icon

Awarded Best Reply on If Statement Laravel

@snipesnipes [email protected]($find > 0), add a space and it will work LIKES @if($find > 0).

Activity icon

Replied to If Statement Laravel

@snipesnipes [email protected]($find > 0), add a space and it will work LIKES @if($find > 0).

Activity icon

Replied to If Statement Laravel

@snipesnipes wrap it with ```.

Activity icon

Replied to If Statement Laravel

@snipesnipes can you post your view code?

Because the code you've posted works without any problems:

@if(true)
   bla bla

   @if(true)
      bla bla
   @endif
@else
   blabla
@endif
Activity icon

Replied to Cancel Redirection On Login

@paubach what about:

protected function authenticated(Request $request, $user)
{
   return response('', 200);
}
Activity icon

Awarded Best Reply on How To Add A A Property To My Collection?

@martinzeltin one of the options:

$collection->transform(function($item) {
   if($item['user_id'] === 73) {
      return array_merge($item, [
         'age' => 25,
      ]);
   }

   return $item;
});
Activity icon

Replied to Cancel Redirection On Login

@paubach make sure you import Request class. Add this at the top:

use Illuminate\Http\Request;
Activity icon

Replied to How To Add A A Property To My Collection?

@martinzeltin one of the options:

$collection->transform(function($item) {
   if($item['user_id'] === 73) {
      return array_merge($item, [
         'age' => 25,
      ]);
   }

   return $item;
});