Sti3bas

Member Since 2 Years Ago

Experience Points
200,580
Total
Experience

4,420 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
1113
Lessons
Completed
Best Reply Awards
150
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]asts.com 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 41
200,580 XP
Jan
27
10 hours ago
Activity icon

Replied to Error In Datetime - SQL Server And Laravel

@cridiba99 you can create your own Model which extends Laravel's Model and add it there. Then update all of your models to extend your own model instead of default one.

app/Model.php:

namespace App;

use Illuminate\Database\Eloquent\Model as BaseModel;

class Model extends BaseModel
{
   public function fromDateTime($value)
   {
      return Carbon::parse(parent::fromDateTime($value))->format('Y-d-m H:i:s');
   }
}

app/SomeModel.php:

namespace App;

class SomeModel extends Model
{
   //...
}

You just have to remove use Illuminate\Database\Eloquent\Model; so that it would extend from App\Model, which is in the same namespace, so you don't have to import it.

Jan
26
1 day ago
Activity icon

Awarded Best Reply on Error In Datetime - SQL Server And Laravel

@cridiba99

public function fromDateTime($value)
{
    return Carbon::parse(parent::fromDateTime($value))->format('Y-d-m H:i:s');
}

https://stackoverflow.com/questions/35457412/laravel-sqlsrv-unable-to-create-timestamps

Jan
25
2 days ago
Activity icon

Awarded Best Reply on Laravel SortCollection

@t0berius 25.01 is not a correct time, so strtotime returns false, that's why it's at the bottom. What if you sort it as float values?:

->sortByDesc(function ($item, $key) {
   return (float)$key;
})

Result:

Illuminate\Support\Collection {#257 ▼
  #items: array:11 [▼
    "25.01" => 0
    "24.01" => 0
    "23.01" => 0
    "22.01" => 0
    "21.01" => 0
    "20.01" => 0
    "19.01" => 4
    "18.01" => 0
    "17.01" => 0
    "16.01" => 0
    "15.01" => 0
  ]
}
Activity icon

Replied to Phpmyadmin With Artisan Serve

@thorbym why do you need it locally? Just use some GUI tool like https://www.sequelpro.com or https://tableplus.com

Activity icon

Replied to Laravel SortCollection

@t0berius 25.01 is not a correct time, so strtotime returns false, that's why it's at the bottom. What if you sort it as float values?:

->sortByDesc(function ($item, $key) {
   return (float)$key;
})

Result:

Illuminate\Support\Collection {#257 ▼
  #items: array:11 [▼
    "25.01" => 0
    "24.01" => 0
    "23.01" => 0
    "22.01" => 0
    "21.01" => 0
    "20.01" => 0
    "19.01" => 4
    "18.01" => 0
    "17.01" => 0
    "16.01" => 0
    "15.01" => 0
  ]
}
Activity icon

Awarded Best Reply on Save Vue Js Components In Separate File

@stefan7

webpack.mix.js:

mix.js('resources/assets/js/app.js', 'js')
  .js('resources/assets/js/admin.js', 'js')
  .version();

Admin layout blade file:

<script src="{{ mix('/js/admin.js') }}"></script>

You should use mix helper to load your compiled assets if you want it to append the hashes.

https://laravel.com/docs/6.x/mix#versioning-and-cache-busting

Jan
24
3 days ago
Activity icon

Awarded Best Reply on Logout 419 Page Expired Vue JS

<input type="hidden" name="_token" :value="csrf">
computed: {
        csrf() {
            return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
        },
}
Activity icon

Replied to Creating A Simple Activity Logger

Do you think this approach is a little rudimentary? I just don't like over complicating for the sake of it.

It depends on your use case. If you want to store activity for multiple models, then that's exactly what you need.

Also, because the model can be null, should I do this?

'model_name' => $event->model ? get_class($event->model) : null,
'model_id' => optional($event->model)->id,
Activity icon

Replied to Creating A Simple Activity Logger

@jesse_orange_newable take a look at get_class function: https://www.php.net/manual/en/function.get-class.php

public function handle($event)
{
   $event->user->activities()->create([
      'type' => $event->type,
      'description' => $event->description,
      'model_name' => get_class($event->model),
      'model_id' => $event->model->id,
   ]);
}
Activity icon

Replied to Remove Images From Storage Folder In Laravel

public function destroy($id)
{
   $avatar = Avatar::findOrFail($id);

   if(Storage::delete($avatar->filename)) {
      $avatar->delete();
   }
   
   return redirect('/avatars');
 }

https://laravel.com/docs/6.x/filesystem#deleting-files

Activity icon

Replied to How To Call Artisan Command From Controller And Run It In Background

Or just queue a closure:

dispatch(function () {
    Artisan::call('some:command');
});

https://laravel.com/docs/6.x/queues#queueing-closures

Activity icon

Replied to Logout 419 Page Expired Vue JS

<input type="hidden" name="_token" :value="csrf">
computed: {
        csrf() {
            return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
        },
}
Activity icon

Replied to Error In Datetime - SQL Server And Laravel

@cridiba99

public function fromDateTime($value)
{
    return Carbon::parse(parent::fromDateTime($value))->format('Y-d-m H:i:s');
}

https://stackoverflow.com/questions/35457412/laravel-sqlsrv-unable-to-create-timestamps

Activity icon

Replied to How To Make PHP Form Refer To A Value On The Same HTML Page?

@uccdev

<input type="radio" name="myOtherInput" onchange="document.getElementsByName('sort')[0].value=this.value" value="x">
Activity icon

Replied to Save Vue Js Components In Separate File

@stefan7 if you only want to load BannerComponent in your admin panel, then you only need to add it to admin.js.

Activity icon

Replied to Why Laravel 5.3 Phpunit So Slow When Using Faker

@prrng are you using bcrypt in your factories?

Activity icon

Replied to Invalid Route Action

@itsfg seems like it should be App\Http\Controllers\Attachments\GetAttachmentController, not Attachments\GetAttachmentController?

You should probably change 'namespace' => '\Attachments' to 'namespace' => 'Attachments' (remove backslash).

Activity icon

Replied to Save Vue Js Components In Separate File

@stefan7

webpack.mix.js:

mix.js('resources/assets/js/app.js', 'js')
  .js('resources/assets/js/admin.js', 'js')
  .version();

Admin layout blade file:

<script src="{{ mix('/js/admin.js') }}"></script>

You should use mix helper to load your compiled assets if you want it to append the hashes.

https://laravel.com/docs/6.x/mix#versioning-and-cache-busting

Activity icon

Replied to Override Default Auth Routes In Laravel 6

@a_mohammad you can disable register route by adding this to your routes file:

Auth::routes(['register' => false]);

You can override login redirection route in RouteServiceProvider, by changing HOME constant to /dashboard: https://github.com/laravel/laravel/blob/master/app/Providers/RouteServiceProvider.php#L24

Activity icon

Awarded Best Reply on Getting Validation Errors From Laravel Excel

@finchy70 where do you see the difficulties?

@if ($failures)
   <div class="alert alert-danger" role="alert">
      <strong>Errors:</strong>
      
      <ul>
         @foreach ($failures as $failure)
            @foreach ($failure->errors() as $error)
                <li>{{ $error }}</li>
            @endforeach
         @endforeach
      </ul>
   </div>
@endif
Jan
23
4 days ago
Activity icon

Awarded Best Reply on Database Validation Using Exists With Array

@leachcreative you can easily verify it:

\DB::enableQueryLog();
    
$request->merge([
   'ids' => [1, 2, 3]
]);

try {
   $request->validate([
      'ids.*' => 'exists:table_name,id',
   ]);
} catch (\Exception $e) {}

dd(\DB::getQueryLog());

Result:

array:3 [▼
  0 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 1
    ]
    "time" => 2.25
  ]
  1 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 2
    ]
    "time" => 0.72
  ]
  2 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 3
    ]
    "time" => 0.86
  ]
]

which means that multiple queries are executed.

Activity icon

Replied to Check If Has Value In An Object Array

The some() method tests whether at least one element in the array passes the test implemented by the provided function.

verifyHasTitle(title) {
   return this.posts.some(post => post.title === title);
}

It will return boolean value.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some

Activity icon

Replied to Database Validation Using Exists With Array

@leachcreative you can easily verify it:

\DB::enableQueryLog();
    
$request->merge([
   'ids' => [1, 2, 3]
]);

try {
   $request->validate([
      'ids.*' => 'exists:table_name,id',
   ]);
} catch (\Exception $e) {}

dd(\DB::getQueryLog());

Result:

array:3 [▼
  0 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 1
    ]
    "time" => 2.25
  ]
  1 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 2
    ]
    "time" => 0.72
  ]
  2 => array:3 [▼
    "query" => "select count(*) as aggregate from `table_name` where `id` = ?"
    "bindings" => array:1 [▼
      0 => 3
    ]
    "time" => 0.86
  ]
]

which means that multiple queries are executed.

Activity icon

Replied to How To Give User Login Option In Laravel Socialite Azure

$user = User::where('email', $azureUser->email)
   ->orWhere('username', $azureUser->mailNickname)
   ->first();
Jan
22
5 days ago
Activity icon

Replied to Vue Js Sweetalert 2 Modal Issue

@atef95 it's not possible by default, take a look at this issue, it has few workarounds: https://github.com/avil13/vue-sweetalert2/issues/59

Jan
21
6 days ago
Activity icon

Replied to Edit Modal Form Only Display One Value

Add data-max-score and data-parent-id attributes to your button:

<button type="button" class="btn btn-sm btn-primary mr-1 edit-category" data-toggle="modal" data-target="#editCategoryModal" data-id="{{ $category->id }}" data-name="{{ $category->name }}" data-max-score="{{ $category->max_score }}" data-parent-id="{{ $category->parent_id }}">Edit</button>

Add this to your js:

var parentId = $(this).data('parent-id');
var maxScore = $(this).data('max-score');

$('#editCategoryModal form select[name="parent_id"]').val(parentId);
$('#editCategoryModal form input[name="max_score"]').val(maxScore);
Activity icon

Replied to How To Link Which Are In Different Folder

@heynibbi the default login view extends layouts.app view: https://github.com/laravel/ui/blob/1.x/src/Auth/bootstrap-stubs/auth/login.stub#L1

If you want to tweak the default navbar, you should do that in views/layouts/app.blade.php file.

Activity icon

Replied to How To Prevent To Go To The Next Tab In Vue-form-wizard?

@mostafalaravel if your beforeTabSwitch function returns false, tab switch will be restricted.

Activity icon

Replied to How To Link Which Are In Different Folder

@heynibbi yes, the code above will include views/layouts/navbar.blade.php in your login page.

Activity icon

Replied to How To Link Which Are In Different Folder

@include('layouts.navbar')
Jan
20
1 week ago
Activity icon

Awarded Best Reply on Display A Message If Login Fails In Laravel Socialite Authentication

@noblemfd just use try...catch block:

try {
   $azureUser = Socialite::with('azure')->user();
} catch(\Exception $e) {
   session()->flash("error", "Your error message");

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

Then in your view show the message:

@if(session()->has('error'))
   <p>{{ session()->get('error') }}</p>
@endif
Activity icon

Replied to Display A Message If Login Fails In Laravel Socialite Authentication

@noblemfd just use try...catch block:

try {
   $azureUser = Socialite::with('azure')->user();
} catch(\Exception $e) {
   session()->flash("error", "Your error message");

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

Then in your view show the message:

@if(session()->has('error'))
   <p>{{ session()->get('error') }}</p>
@endif
Activity icon

Awarded Best Reply on Checking Variable Contents In Laravel

@konrms you can use collection's contains method:

$items = collect($my_var);

if($items->contains("object_id", "50165685") && $items->contains("object_id", "50165686")) {
   $new_variable = "blablabla";
}

https://laravel.com/docs/6.x/collections#method-contains

Activity icon

Replied to Checking Variable Contents In Laravel

@konrms you can use collection's contains method:

$items = collect($my_var);

if($items->contains("object_id", "50165685") && $items->contains("object_id", "50165686")) {
   $new_variable = "blablabla";
}

https://laravel.com/docs/6.x/collections#method-contains

Jan
18
1 week 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
1 week 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