Member Since 3 Years Ago


Experience Points 76,890
Experience Level 16

3,110 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 512
Best Reply Awards 39
Best Reply
  • 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.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    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.

28 Jun
1 month ago

BezhanSalleh left a reply on Check If User Is Active In Laravel 5.4

@mirzanayeem in your view via session helper:

@if( session()->has('info') )
    {{ session('info') }}

next time... create a new question don't post on old threads. that way you will get a quick response... ~cheers

25 Nov
8 months ago

BezhanSalleh left a reply on Verify Password Is The Same , And Update It .

namespace App\Http\Controllers;
use Auth;
use Hash;
use Illuminate\Http\Request;

class ChangePasswordController extends Controller
    public function __construct()
    public function showChangePasswordForm(){
        return view('auth.changepassword');
    public function changePassword(Request $request){
        if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
            // The passwords matches
            return redirect()->back()->with("error","Your current password does not matches with the password you provided. Please try again.");
        if(strcmp($request->get('current-password'), $request->get('new-password')) == 0){
            //Current password and new password are same
            return redirect()->back()->with("error","New Password cannot be same as your current password. Please choose a different password.");
        $validatedData = $request->validate([
            'current-password' => 'required',
            'new-password' => 'required|string|min:6|confirmed',
        //Change Password
        $user = Auth::user();
        $user->password = bcrypt($request->get('new-password'));
        return redirect()->back()->with("success","Password changed successfully !");

Route::get('/changePassword','ChangePasswordController[email protected]');
Route::post('/changePassword','[email protected]')->name('changePassword');

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Change password</div>

                    <div class="card-body">
                        @if (session('error'))
                            <div class="alert alert-danger">
                                {{ session('error') }}
                        @if (session('success'))
                            <div class="alert alert-success">
                                {{ session('success') }}
                        <form class="form-horizontal" method="POST" action="{{ route('changePassword') }}">

                            <div class="form-group{{ $errors->has('current-password') ? ' has-error' : '' }}">
                                <label for="new-password" class="col-md-4 control-label">Current Password</label>

                                <div class="col-md-6">
                                    <input id="current-password" type="password" class="form-control" name="current-password" required>

                                    @if ($errors->has('current-password'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('current-password') }}</strong>

                            <div class="form-group{{ $errors->has('new-password') ? ' has-error' : '' }}">
                                <label for="new-password" class="col-md-4 control-label">New Password</label>

                                <div class="col-md-6">
                                    <input id="new-password" type="password" class="form-control" name="new-password" required>

                                    @if ($errors->has('new-password'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('new-password') }}</strong>

                            <div class="form-group">
                                <label for="new-password-confirm" class="col-md-4 control-label">Confirm New Password</label>

                                <div class="col-md-6">
                                    <input id="new-password-confirm" type="password" class="form-control" name="new-password_confirmation" required>

                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-4">
                                    <button type="submit" class="btn btn-primary">
                                        Change Password

BezhanSalleh left a reply on Track How Many Users Online In Real Time?

check this it might help you get started then maybe you could use pusher or to check online presence of users and guests(visitors) in realtime... cheers

22 Aug
11 months ago

BezhanSalleh left a reply on Multiple Authentication - Larvel 5.6 - Tutorial - Suggestion

Depends on your needs really... You can use hesto/multi-auth package or tinker with it and whip something yourself...

13 Jun
1 year ago

BezhanSalleh left a reply on How To Identify User When Sending A Data Via Socket

i haven't used electron but i think this package might give an idea on how to implement your specific scenario.

a post on medium with more explaination

just fyi PWAs might be easy then electron...just a thought


BezhanSalleh left a reply on Laravel Update From Logged In User

buddy your relationships are not properly defined. from what i can see users-locations relationship is m-m and then you a have created a model for the pivot table which is location_user... so in your

//User model
    public function locations()
        return $this->belongsToMany(Location::class,'location_users')

//Location model
    public function users()
        return $this->belongsToMany(User::class,'location_users')
//LocationUser model
    //you don't have to define these when you use belongsToMany
    //either use the 1-m relation between them and then define the inverse
    // but if you need them while using belongsToMany for some reason 
    //define them properly
    public function user() {
        return $this->belongsTo(User::class, 'id', 'user_id');

    public function location() {
        return $this->belongsTo(Location::class, 'id', 'location_id');
// now from what i see in your controller your are trying the 1-m approach so

public function edit(LocationUser $LocationUsers)
    // this way when the user clicks on a departure other his own
    // he/she will be redirected with Failure msg
    if(auth()->Id() != $locationUsers->user->id))
            return redirect()->back()->withFailure('You are Not Authorized');   
    return view('departure.edit', compact('LocationUsers'));    

public function update(Request $request, LocationUser $LocationUsers)
    // to make it more secure here you could validate the requested
    // departure_date and since you have only one field its better to only request
    // that particular field instead given the user a chance to send malicious data
    $LocationUsers->update(['departure_date' => $request->input('departure_date')]);

    return redirect()->route('home', $LocationUsers)
        ->withSuccess('Departure updated!');

The above will solve your problem given you should check and correct your relationships and follow the laravel grammer. but the best way to do this would be to update your index so the logged in user should only see his/her own departure_dates only

//your index method for departure might look something like following i suppose

public function index()
    $LocationUsers = LocationUser::latest()->paginate(10);//or ->get();
    return view('departure.index',compact('LocationUsers'));

now updating the above as follow won't give the use a chance to see others departure dates

public function index()
    $locationUsers = LocationUser::where('user_id',auth()->id())
    //$locationUsers = LocationUser::whereHas('user',function($user){
    //                              $user->whereId(auth()->id());
    //                          })->paginate(10);//->get();
    return view('departure.index',compact('LocationUsers'));

my advice would be to master the eloquent relationships first so you wouldn't have any problems in the feature... it might look a little bit confusing at first but once you get to know them its really fun. now i don't wanna go through the m-m situation which might confuse and since you have been doing this approach which works but its not the proper way.... just search and i hope it helps. and for security use one of the many packages for the roles and permissions based packages or look into laravel's own gate and policies... Happy Laraveling! ~cheers

BezhanSalleh left a reply on Laravel Update From Logged In User

could you share your models for user and LocationUsers??? it seems while editing you are not checking whether the user is authorized or not;

in your edit you could do

if(auth()->user()->locationUser == $LocationUser)
    //return the vies to edit
    // return with unauthorized

or you could use policies for this or a roles or permission package...

BezhanSalleh left a reply on Pagination Problem In Search Option In Laravel

I would go with query scope

but you can checkout the following links

QueryScope Example: or give this a try... on mobile haven't tested but the logic is sound so you might not run into any problem... it readable which is supposed to be... any problems let me know.. cheers...


public function index(Request $request)
        $products = Product::search($request->keyword)
        return view('products._searchResult',compact('products'));

    return view('products.index', compact('products'));


Route::resource('products', 'ProductsController');
//Product Model

public function scopeSearch($query,$keyword)
    $query->where('name','like',"%$keyword%");// add as many column searchs as you wants 



        @foreach($products as $product)
            <li>{{ $product->name }}</li>
            <li>{{ $product->category->name }}</li>
            <li>{{ $product->package->type }}</li>
{!! $product->links() !!}

<div class="form-group">
    <input type="text" name="keyword" class="form-control" id="keyword" />

<div id="list">

        var search = $(this).val();
            url: '{{ route('products.index') }}',
            type: 'get',
            data: {keyword: 'search'},
        .done(function(data) {
        .fail(function() {
        .always(function() {

10 Apr
1 year ago

BezhanSalleh left a reply on Restful API In Laravel 5.6

cheers mate! :)

BezhanSalleh left a reply on Why My Laravel Website Is So Slow?

combine your assets into a single file... if you are using laravel-mix it will be a breeze.

BezhanSalleh left a reply on Property [name] Does Not Exist On This Collection Instance.

because the relation is m2m, you can't just say $row->roles->name. try the following

    @foreach($row->roles as $role)
        {{$role->name.' - ' }} //or however you display them.

BezhanSalleh left a reply on Relations. Get Only One Item.

that's because your relations are not properly defined. in your MagasineSubcategory model update the products method as follow

    public function products()
        return $this->belongsToMany('App\Product', 'product_has_subcategories', 'subcategory_id','product_id');

BezhanSalleh left a reply on Relations. Get Only One Item.

what's your goal here? you haven't really cleared what it is that you want. you want one product returned or Multiple? if its the latter then you need to update this line in your controller:

$produkty_subkategoria = MagazineSubcategory::with('products')
                            ->where('name', 'wiertarki')
return $produkty_subkategoria;
07 Apr
1 year ago

BezhanSalleh left a reply on How Do You Change The Default Id That Gets Passed Into The Controller?

@p0t4t0 you wanna use the route model binding, specifically, implicit route model binding... and you want username instead of the default id ...which is that method does. again read this...


public function getRouteKeyName()
    return 'username';

Route::get('profile/{user}', '[email protected]');

public function(User $user) {
    $product = Product::where('username',$user->username)->first();
// now you will be able to access

also i would recommend using another controller like ProfilesController, as the functionality grows you can keep track of what's where and so on..

BezhanSalleh left a reply on How Do You Change The Default Id That Gets Passed Into The Controller?

in your user model,

public function getRouteKeyName()
    return 'username';

your route is ok, just in your controller

public function profile($username){
    $product = Product::whereUserName($username)->firstOrFail();

just refer to the docs for explanation

10 Mar
1 year ago

BezhanSalleh left a reply on Multiple And Advance Authorization With Different Tables

checkout the article Povilas Korop wrote on all your questions will be answered.

BezhanSalleh left a reply on Select Game With Screenshot Relationship But Only Where Screenshots Exist. Query Not Working

@madsem accepted or not doesn't matter, all that matter is that it helped you get what you were looking for and i'm glad that it did. cheers mate!

08 Mar
1 year ago

BezhanSalleh left a reply on Select Game With Screenshot Relationship But Only Where Screenshots Exist. Query Not Working

change with to whereHas that way you will get what you want...

Game::whereHas( 'screenshots' => function ($query) {
                   $query->where('size_label', '=', 't_screenshot_huge');
             ->where('hypes', '>', 1)

BezhanSalleh left a reply on Eloquent Api Resource Upgrade To 5.6

as in the upgrade guide: The original property of resource responses is now set to the original model instead of a JSON string / array. This allows for easier inspection of the response's model during testing.

BezhanSalleh left a reply on User / Admin Auth In Laravel 5.2

@Ramnish this an old thread buddy... next time make a new thread and post your question there... anyways it depends on what kinda of functionality you want... you can give a look the following and chose whichever one best suits your need... keep in mind though some of them includes extra features that you might not need... ~ cheers mate!

22 Feb
1 year ago

BezhanSalleh left a reply on Combine Where And Has

just a side note you CAN use whereHas too...

->whereHas('checks',function($checks) //if you are passing a variable you should do a use($variable)

but as @Snapey said, its not clear, you should post your models and a sample of what are you trying to achieve. ~cheers

09 Feb
1 year ago

BezhanSalleh left a reply on Dynamic Table Name

@me_macfly yeah the controller should be what you said and yeah it will since you are changing the table for the model.

// Controller.php
$product = new Product;
$product->bind('mysql', $category->name.'_products' );

$products[] = $product->where('user_id',auth()->id())->get();

the newInstance method part is for when you want to perform any insert on the model after you dynamically change the table. for situations like

$product = new Product;
$product->getTable(); // products
$product->bind('mysql', $category_product);
$product->get(); // select * from $category_product
$product->first(); // select * from $category_product limit 1

// with the newInstance method you will be able to do the following.
$product->column = 'test'; //$category_product->column
// if you just wanna perform selects then you can remove that part but if you later on need to change something leave it as it is.

08 Feb
1 year ago

BezhanSalleh left a reply on How Do You Send A First Time User A Password Reset Link? (

in this case on creation send an email with their username and system generated password and when a user is authenticated using their system generated password that's the first time show the reset password form. Et Voila!

BezhanSalleh left a reply on How Do You Send A First Time User A Password Reset Link? (

yeah, but if you are verifying the email then you send the user to the reset page and after reset to the login page. and you probably have a change password option for the authenticated user. for a first time user seems lots of hoop to jump over.

My way Verify->Authenticate->Reset by leveraging the change password option if exist->boom!

BezhanSalleh left a reply on How Do You Send A First Time User A Password Reset Link? (

i would show the reset password for the new registered user after he/she is authenticated (or verified their email if verification is involved) for the first time and after that business as usual.

BezhanSalleh left a reply on Dynamic Table Name

the post that @bobbybouwmann mentioned earlier is your solution... you just didn't look in the right place. the selected answer has a problem which is already explained in the one just after that. give this a try:

// BindsDynamically.php
trait BindsDynamically
    protected $connection = null;
    protected $table = null;

    public function bind(string $connection, string $table)

    public function newInstance($attributes = [], $exists = false)
        // Overridden in order to allow for late table binding.

        $model = parent::newInstance($attributes, $exists);

        return $model;

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model

    use BindsDynamically;

    public function user()
        return $this->belongsTo( User::class );

// YourController.php
        $categories = Category::orderBy( 'name', 'desc' )->get();

        foreach ($categories as $category)
        $product = auth()->user()->products()->first();
            //replace connection with your db connection name 'mysql' if you are using it...
        $product->bind('connection', $category.'_products'); 
        //$product->get(); //select * from $category_products [categorya_products...]
            // not 100% sure about this auth()->user()->products()->get(); so
            $products[] = $product->where('user_id',auth()->id())->get();

this should work...

BezhanSalleh left a reply on Permissions Optimization In Blade

You need to separate the logic for your modules or submodules that are accessible only by permission. Suppose in your example if you want your users to be able to view reports no matter what their roles are, given you want them to be able to view the reports based on the permission alone; you would need to implement the logic as follow:

    //first checks the role and then the permission if has it allow if not you know
    @if( $user->isAn('role1', 'role2', 'etc'))

                Icon - Orders

                Icon - Suppliers
    //here only checks the permission if has the permission allows it.
        Icon - Reports
            <li>Report 1</li>
            <li>Report 2</li>
            <li>Report 3</li>

cheers mate!

31 Jan
1 year ago

BezhanSalleh left a reply on Why Laravel Error File Permission

he's on windows... :P

BezhanSalleh left a reply on Why Laravel Error File Permission

if you are referring to delete a file from storage through your application then you need to set the right permissions for that. use your backup and set up your project as before you delete it. Once you set up your application then follow the steps below:

1. open your application //Fani-Serve-Side
2. right click on storage -> properties -> security -> Edit
3. then chose the option that looks something like Users (YourComputerName\Users)
4. Now you see the same window but the check boxes are enabled -> check Full Controll
5. Apply -> Ok


Now everything should be working!

... cheers mate!

to remove your project entirely: open command prompt as admin then then type rd -r F:\xampp\htdocs\Fani-Server-Side hit enter or type rd F:\xampp\htdocs\Fani-Server-Side /S /Q hit enter.

BezhanSalleh left a reply on Laravel

@bobbybouwmann this one Eloquent Techniques: Dedicated Query String Filtering

BezhanSalleh left a reply on Single Page App With Autocompletion And Browser Back Button!

if you only need the back button then you can use a url helper url()->previouse().

<a href="{{ url()->previous() }}">Back</a>

BezhanSalleh left a reply on Is It A Good Idea To Have Controller Files For Admin User Stored In A Separate Folder Called Admin.

It is a good idea. all you have to do though, is create a folder by whatever name you like. In your case admin. Since you created the admin directory inside the Controllers directory you don't need to copy or move the controller class. remove the Controller.php from your admin directory and your problem will be solved. Or if you really need that Controller class to provide some other feature than the normal controller then amend your import path:

use App\Http\Controllers\admin\Controller;

if it does what the normal one does, then go with the first option.

BezhanSalleh left a reply on Show In Blade

having fun guys ha! .. you guys are terrible...


// update your code to
$data = [
$hasilSum = 0;
foreach($data as $value){
    $hasilSum += $value["total"];

return view('your_view_name', compact('data','hasilSum'));

// then in your_view_name.blade.php
@foreach($data as $value)
    {{"persentase partai ".$value["title"].": ".number_format(($value["total"]/$hasilSum)*100,2)."%"}} <br>
30 Jan
1 year ago

BezhanSalleh left a reply on Foreach Array

post your could as I showed you earlier...

BezhanSalleh left a reply on Deploying Laravel On Shared Hosting Apache Server - Making Public Is The Root Document

yes, since your domain points to the public folder for accessing your web app you need to amend the paths accordingly, otherwise it won't work.

checkout this everything is explained here and the four methods you can deploy on shared hosting and what's best and why...

BezhanSalleh left a reply on How To Validate Date After_or_equal To A Column

if your condition is gte than unique is out of the question unless you combine some other column with it. won't this solve your problem though date|nullable|unique:revisions,effective_date|after:effective_date

BezhanSalleh left a reply on Retrieve Object Throught Many Models

no worries mate, happens to the best of us...


BezhanSalleh left a reply on How To Validate Date After_or_equal To A Column

if your using carbon then i don't see the point since you are checking the >= for revision creation. anyhow you could try something as follow:

$post = Post::find(1);
//for post 1 get last revision's effective_date
$last_effective_date = $post->revisions()->select('effective_date')->latest()->first()->created_at;
//check to see if the last effective date for post one is greater than or equal to the current date
    //if the condition passes create a new revision for the post 1
        'other_fields' => $someValue,
        'effective_date' => Carbon::now()
29 Jan
1 year ago