BezhanSalleh

BezhanSalleh

Kabul

Member Since 2 Years Ago

Experience Points 68,120
Experience
Level
Lessons Completed 428
Lessons
Completed
Best Reply Awards 39
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

25 Nov
2 weeks ago

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

~~ Controller::ChangePasswordController.php

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

check this https://github.com/joshrainwater/active-users it might help you get started then maybe you could use pusher or sockets.io to check online presence of users and guests(visitors) in realtime... cheers

22 Aug
3 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 whip something yourself...

25 Jun
5 months ago

BezhanSalleh left a reply on Return Posts Ranked By Number Of Associated Comments.

give this a try...

$post = Post::join('comments','posts.id','=','comments.post_id')
        ->select('posts.*',DB::raw('count(comments.id) as count')
        ->orderBy('count','desc')
        ->limit(10)
        ->get();

~cheers

13 Jun
5 months 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.

https://www.npmjs.com/package/socketio-auth

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

~cheers

BezhanSalleh left a reply on Laravel Update From Logged In User

buddy your relationship 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')
                ->withPivot('departure_date');
    }

//Location model
    public function users()
    {
        return $this->belongsToMany(User::class,'location_users')
                ->withPivot('departure_date');
    }
//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())
                        ->paginate(10);
    //or
    //$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 just search and i hope it helps. 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... }else{ // return with unauthorized }

10 Apr
8 months ago

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 relations is m2m, you can't just say $user->roles->name. try the following

<td>
    @foreach($user->roles as $role)
        {{$role->name.' - ' }} //or however you display them.
    @endforeach
</td>
~~

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

that's because your relations are not properly defined. in your MagasineSubcategory 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 How To Pass Id From View To Route And From Route To Controller

start with ~~~
    paste your code
end with ~~~

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 from 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')
                            ->get();
return $produkty_subkategoria;
07 Apr
8 months 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... https://laravel.com/docs/5.5/routing#implicit-binding

//User.php

...
public function getRouteKeyName()
{
    return 'username';
}
...

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

public function(User $user) {
    //
    $user->username
}
// now you will be able to access
site.com/profile/potato

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';
}

in your controller

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

just refer to the docs for explanation https://laravel.com/docs/5.6/routing#customizeing-the-key-name

10 Mar
9 months ago

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

checkout the article PovilasKorop wrote on laravel-news.com. all your questions will be answered. https://laravel-news.com/two-best-roles-permissions-packages

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
9 months ago

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

try this...

Game::whereHas([
                'screenshots' => function ($query) {
                    $query->where('size_label', '=', 't_screenshot_huge');
                }
            ])->where('hypes', '>', 1)->orderByRaw('RAND()')->take(3)->get();

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.

checkout the upgrade guide https://laravel.com/docs/5.6/upgrade

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! https://github.com/appzcoder/laravel-admin https://github.com/viralsolani/laravel-adminpanel http://laraadmin.com/ https://tutorials.kode-blog.com/laravel-5-admin-panel https://github.com/Labs64/laravel-boilerplate https://github.com/sebastienheyd/boilerplate

22 Feb
9 months ago

BezhanSalleh left a reply on Combine Where And Has

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

$user->organisation->records()->with('payments','checks.location')
->whereHas('checks',function($checks){
        $checks->where('yourConditionHere',$);
    })
->paginate();

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
10 months ago

BezhanSalleh left a reply on Dynamic Table Name

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
$product->save();
// 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
10 months 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 show he reset form.

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 leverage 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 bussiness as usual.

BezhanSalleh left a reply on Dynamic Table Name

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

    public function bind(string $connection, string $table)
    {
        $this->setConnection($connection);
        $this->setTable($table);
    }

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

        $model = parent::newInstance($attributes, $exists);
        $model->setTable($this->table);

        return $model;
    }

}
//Product.php 
namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{

    use BindsDynamically;

    public function users()
    {
        return $this->belongsTo( User::class );
    }

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

        foreach ($categories as $category)
        {
        $product = auth()->user()->products()->first();
            $product->getTable();
        $product->bind('connection', $category.'_products');
        //$product->get(); //select * from $category_products
            $products[] = auth()->user()->products()->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 for you wanted 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:

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

            @can('view-orders')
            <li>
                Icon - Orders
            </li>
        @endcan

            @can('view-suppliers')
            <li>
                Icon - Suppliers
            </li>
            @endcan
    @endif
    //here only checks the permission if has the permission allows it.
    @can('view-reports')
    <li>
        Icon - Reports
        <ul>
            <li>Report 1</li>
            <li>Report 2</li>
            <li>Report 3</li>
        </ul>
    </li>
    @endcan
</ul>

cheers mate!

31 Jan
10 months ago

BezhanSalleh left a reply on Why Laravel Error File Permission

@deansatch you are right. but I didn't intend to do that..., he didn't really explain what he wanted, i thought he just wanted to delete his app. and given his os was windows so...

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

@jaffar98 that's what you wanted. right?

BezhanSalleh left a reply on Why Laravel Error File Permission

open command prompt as admin then then rd F:\xampp\htdocs\Fani-Server-Side /S /Q

BezhanSalleh left a reply on Laravel Searching

@bobbybouwmann this one Eloquent Techniques: Dedicated Query String Filtering https://laracasts.com/series/eloquent-techniques/episodes/4

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 Files Called Admin.

Since you have created the admin directory inside the Controllers directory you don't need to copy or move the base controller class. remove the Controller.php from your admin directory and your problem will be solved.

BezhanSalleh left a reply on Show In Blade

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

// update your code to
$data = [
            [
                "title"=>"PKS",
                "total"=>100
            ],
            [
                "title"=>"Gerinda",
                "total"=>30
            ]
        ];
$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)."%"}} <br>
@endforeach
30 Jan
10 months 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 http://blog.netgloo.com/2016/01/29/deploy-laravel-application-on-shared-hosting/ 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 Validation Is Not Working Within Foreach!!

first where is your opening and closing form tag, your form method and route? post your route and add the the opening and closing form tag with the method and action which is the route or url your posting the data to.

not that it matters right now, you are sending null values. but once your route and form tags have been cleared then it would create a problem.

try this

//you should have a route
Route::post('/whatever/the/url', '[email protected]')->name('productAttributes.store');
//your views
{!! Form::open(['route' => 'productAttributes.store','method'=>'POST']) !!}
    @foreach($attrs as $attr)
        {!! Form::text('attrvalue_1', $attr->attribute_1, array('placeholder' => '','class' => 'form-control')) !!}
        {!! Form::text('attrvalue_2', $attr->attribute_2, array('placeholder' => '','class' => 'form-control')) !!}
        {!! Form::text('attrvalue_3', $attr->attribute_3, array('placeholder' => '','class' => 'form-control')) !!}
    @endforeach

{!! Form::close() !!}

i assume you are posting not updating...

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.

BezhanSalleh left a reply on Retrieve Object Throught Many Models

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

~cheers