BezhanSalleh

Experience

20,380

15 Best Reply Awards

  • Member Since 1 Year Ago
  • 115 Lessons Completed
  • 1 Favorite

18th January, 2018

BezhanSalleh left a reply on MySQL: How To RECURSIVELY Sum Values On Different Rows • 1 hour ago

@vincej i update the answer after i unblocked the imgur url from my firewall, saw your img... all you need it was to use DB::raw('sum(table.col) as alias') and losing the ->sum('tbl.col')

BezhanSalleh left a reply on MySQL: How To RECURSIVELY Sum Values On Different Rows • 1 hour ago

@vincej how did you define the relationship between orders and products?

BezhanSalleh left a reply on Create A User Register On Admin Side • 2 hours ago

@dabnad the easy and simple way is to create a UsersController with views for users' CRUD and restrict its access to admin, so the admin could add, delete or update users.

BezhanSalleh left a reply on Auth ID In Constructor, But Also Verifying User 'Auth' • 4 hours ago

@shadrix you can create a middleware like AuthUserId then add it to kernel.php and finally $this->middleware(['auth','authUserID']) or, haven't tested but should work.

  $this->middleware(['auth', function ($request, $next) {
            $this->authUserId = auth()->id();
            return $next($request);
        });
  ]);

BezhanSalleh left a reply on Authentication Problem • 4 hours ago

@sohail302 try to dump the request before the auth condition? see if you are getting the the data from the form, then your problem might be in setting the guard

BezhanSalleh left a reply on Authentication Problem • 5 hours ago

@sohail302 again what's the error? did you run php artisan config:cache after you edit the config/auth.php file?

BezhanSalleh left a reply on Authentication Problem • 5 hours ago

@sohail302 what is the error? have you set the admin guard? btw which laravel version are you on and are you using the laravel basic auth scaffold?

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 6 hours ago

@jahstation well using ready made things has their quarks, so before using/integrating them you gotta know every ins and outs of them which is kinda time consuming... i gave it a look, it has lots of futures that you might not need all 'em, so unless you need all those features i would suggest to make your own template and only require the packages you need through composer, which will be easy to manage and won't affect your performance and more.. ... just a thought. cheers!

BezhanSalleh left a reply on Add Bed In Each Room • 6 hours ago

@devMoaa what is the output? show us the Room and Bed Models...

BezhanSalleh left a reply on RTL Mail Markdown Components • 18 hours ago

you first need to run php artisan vendor:publish then the tag with laravel-mail then navigate to resources\views\vendor\mail\html\themes\default.css.

17th January, 2018

BezhanSalleh left a reply on RTL Mail Markdown Components • 1 day ago

ltr_to_rtl

BezhanSalleh left a reply on RTL Mail Markdown Components • 1 day ago

in resources/vendor/mail/html/themes/ there is a file called default.css update it to RTL, you know lefts to rights and rights to lefts... you get the idea. or use online converter. once done save it and send another email check it you will see... that easy!

BezhanSalleh left a reply on "SluggableServiceProvider.php Does Not Exist Anymore?" • 1 day ago

@javineo in any model that you use Cviebrock\EloquentSluggable\SluggableTrait change it to Cviebrock\EloquentSluggable\Sluggable

BezhanSalleh left a reply on Add Bed In Each Room • 1 day ago

@devMoaa give this a try:

$room = Room::findOrfail('id');
$countBeds = $room->beds()->count();//you can use the relationship to get the counts
$rooms = Room::where('beds','>',$countBeds)->pluck('name','id);//its already an array

BezhanSalleh left a reply on "SluggableServiceProvider.php Does Not Exist Anymore?" • 1 day ago

@javineo ok i forgot on step, after php artisan key:generate run php artisan config:cache again and then run php artisan serve

BezhanSalleh left a reply on "SluggableServiceProvider.php Does Not Exist Anymore?" • 1 day ago

@javineo no, follow the steps

//in app.php set the key as and save it
'key' => env('APP_KEY'),
//then run the following
php artisan config:cache
php artisan key:generate
//now
php artisan serve

that's it

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

the best practice in order to integrate or update something, first test it, create a test project check it out then apply it on your app. So test it first if it works then i guess you have backed up your app then integrate after you workout all the quarks of the new update...

BezhanSalleh left a reply on Problem Adding A Condition To Login • 1 day ago

@Dolce mark the best answer so the thread gets closed, so the users could find the answer easily

BezhanSalleh left a reply on Problem Adding A Condition To Login • 1 day ago

to restrict access if user is not active, implement the authenticated function in the AuthenticatesUsers trait as follow,

public function authenticated(Request $request, $user) { if (!$user->verified) { auth()->logout(); return redirect('/login')->with('info', 'Your account is not activated yet'); } return redirect()->intended($this->redirectPath()); }

BezhanSalleh left a reply on "SluggableServiceProvider.php Does Not Exist Anymore?" • 1 day ago

why are you setting the key manually??? to easily generate a new key whenever you want from console change it to

'key' => env('APP_KEY'),

run

php artisan config:cache
php artisan key:generate

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

@jahstation if you are just testing https://github.com/FlorientR/laravel-gentelella remove it and clone it again...

BezhanSalleh left a reply on Problem Adding A Condition To Login • 1 day ago

@Dolce yes exactly! not on a pc the function names interchanged that was for something else... glad its working...

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

unless you are overriding the default it should be like this

public function handle($request, Closure $next, ...$guards)
{
    $this->authenticate($guards);

    return $next($request);
}

BezhanSalleh left a reply on "SluggableServiceProvider.php Does Not Exist Anymore?" • 1 day ago

change

Cviebrock\EloquentSluggable\SluggableServiceProvider::class,

to

Cviebrock\EloquentSluggable\ServiceProvider::class,

BezhanSalleh left a reply on Problem Adding A Condition To Login • 1 day ago

no! here, your showResetForm function will look something as follow

public function showResetForm(Request $request, $token = null)
{
        $user = User::where('email',$request->email)->first();
        if(!$user->active){
            return redirect('/login')->with('error','YOU ARE REQUIRED TO ACTIVATE YOUR      
                     ACCOUNT FIRST ');
        }

    //before
    return view('auth.passwords.reset')->with(
            ['token' => $token, 'email' => $request->email]
        );
}

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

what works?

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

ok, check something!

in your web.php add the follwing before your auth routes

Route::get('/getUsers', function(){
    return App\User::first();
    //or dd(App\User::first());
});

see if its working... if not the problem might be with the update of laravel-permission from 1.13.0 to 1.15.0 so edit your composer.json and set the version back to 1.13.0... and nothing helps, start again with your recent back up

BezhanSalleh left a reply on Problem Adding A Condition To Login • 1 day ago

in your ResetsPasswords trait just before returning the view check

    public function showResetForm(Request $request, $token = null)
    {
        $user = User::where('email',$request->email)->first();
        if(!$user->active){
            return redirect('/')->with('error','YOU ARE REQUIRED TO ACTIVATE YOUR       
                     ACCOUNT FIRST ');
        }
    // the rest
   }

here you can also check if the user not registered then return with something like, you need to sign up first.

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

haha, no worries, the only way to learn! how did you update the template? unless we see some code, i don't know how to help...

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

did you edit your composer.json file or something, cause unless you didn't change anything in your code or added a new package. composer update won't cause anything like this. not for me anyway... plus why would run composer update if you just wanted to update your template.?

BezhanSalleh left a reply on Column Not Find After Run A "composer Update" • 1 day ago

try

php artisan cache:clear
php artisan config:cache

if that didn't help, show us your controller code for home page and if you have authentication in place your AuthenticatesUsers trait.

12th January, 2018

BezhanSalleh left a reply on Put Data From Database To Chart • 6 days ago

@adnan483 yes you can, just pass the month, use eloquent or querybuilder it would make it much simpler:

$month = $request->input('month');
DB::table('duznicis')
    ->select('Day(created_at) as dan',DB::raw('sum(ukupni_dug) asukupno')
        ->whereMonth('created_at',$month)
        ->groupBy('dan')
        ->get();

BezhanSalleh left a reply on Put Data From Database To Chart • 6 days ago

you might wanna look into this https://laracasts.com/series/charting-and-you

11th January, 2018

BezhanSalleh left a reply on How Can I Save Multiple Columns In A 1:N Relationship • 6 days ago

your values in itself are arrays... you need to do this:

$streets = array_values($request->input('street'));
$districts = array_values($request->input('district'));
$codes = array_values($request->input('code'));
                        'code' => $request->code,
$state_ids = array_values($request->input('id_state'));
$city_ids = array_values($request->input('id_city'));

                        'state_id' => $request->id_state,
                        'city_id' => $request->id_city,


foreach($streets as $key => $value)
{
    $inc->address()->create([
        'street' => $value,
            'district' => array_get($districts,$key),
            'code' => array_get($codes,$key),
            'state_id' => array_get($state_ids,$key),
            'city_id' => array_get($city_ids,$key)
    ]);
}

hope it helps...

BezhanSalleh left a reply on Backup Doesn't Work • 6 days ago

@adnan483 you can't exactly call artisan commands as you would in console. For calling commands with arguments you would have to make an array of parameters for the call methods' second argument: https://laravel.com/docs/5.5/artisan#programmatically-executing-commands

\Artisan::call('backup:run',['--only-db'=>true]);

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

@adnan483 as @Snapey suggested: https://github.com/spatie/laravel-backup this is the best package there is right now, and it has a very through documentation: https://docs.spatie.be/laravel-backup/v3/introduction... create a test project and test the package there not in your real project and give it a try, this way if anything goes wrong you can't just delete the whole thing without affecting your main project.

10th January, 2018

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

@adnan483 check app/Console/Commands/Kernel.php if you have any commands there pretaining to back:mysql-dump delete it duh... next if you are on sublime Ctrl+Shift+F and add backup:mysql-dump for find then in where drive:\www\project_name\,*.blade.php,*.php,*.json,*.* hit enter... you know the rest.

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

@adnan did you do compser update after you removed the package?

BezhanSalleh left a reply on Set Permission For Different Methods In Controller When Using Spatie\Permission • 1 week ago

@Luka it means that you haven't setup the package properly... if you created Role and Permission Models then extend them, if you haven't create them... your error corresponds to the latter... create these it will work

// Role Model
class Role extends \Spatie\Permission\Models\Role 
{
    //
}
class Permission extends \Spatie\Permission\Models\Permission 
{ 
    //
}

BezhanSalleh left a reply on Set Permission For Different Methods In Controller When Using Spatie\Permission • 1 week ago

the better option would be to set the middleware on routes, but if your controller is used by multiple roles just use the or operator like

public function __construct() {
        $this->middleware(['auth', 'isSuperAdmin|isUserAdmin|isNewsOwner|isNewsEditor']); /
}

and in your delete method suppose you don't want anyone else but the SuperAdmin to delete you would do something in the lines of:

public function destroy($id)
{
    if(!auth()->user()->hasRole('SuperAdmin'))
    {
        return back()->with('status','Access Denied or You don't have permission');
    }
    $news = News::findOrFail($id)->delete();
    return back()->with('status','News Deleted');
}

so check the authenticated users' roles and if has the role allow them to do things ... just by

if(auth()->user()->hasRole('your role name to be checked'))
{
    //your logic here
} 

refer to the docs and see what methods you need and check... cheers

BezhanSalleh left a reply on Create Query With Eloquent • 1 week ago

Productcategory::select(DB::raw('count(category_id) as categoryCount','category_id','product_id')
    ->groubBy('category_id')
    ->orderBy('categorycount','desc')
    ->get();

BezhanSalleh left a reply on Group Eloquent • 1 week ago

as long as it works! right...

9th January, 2018

BezhanSalleh left a reply on Group Eloquent • 1 week ago

This is a warning stating that your query is ambiguous, came in MySQL 5.7. the easy options is to add the month in the group by too: ``->groupBy('year','month'); you will be ok.

BezhanSalleh left a reply on Carbon Get Count Of Weeks In Month • 1 week ago

@vandyczech by default Carbon's week day starts from monday, saturdays and sundays are considered as weekends, you can check that by $date->isWeekDay() and isWeekEnd() which returns true or false depending on the day.

i think you want something like this, didn't have much time so see it helps turn it into a function and done..,

Route::get('/enter_month_num/{month}',function($month){
    $year = Carbon::now()->year;
    $date = Carbon::createFromDate($year,$month);
    $numberOfWeeks = floor($date->daysInMonth / Carbon::DAYS_PER_WEEK);
    $start = [];
    $end = [];
    $j=1;
    for ($i=1; $i <= $date->daysInMonth ; $i++) {
        Carbon::createFromDate($year,$month,$i); 
        $start['Week: '.$j.' Start Date']= (array)Carbon::createFromDate($year,$month,$i)->startOfWeek()->toDateString();
        $end['Week: '.$j.' End Date']= (array)Carbon::createFromDate($year,$month,$i)->endOfweek()->toDateString();
        $i+=7;
        $j++; 
    }
    $result = array_merge($start,$end);
    $result['numberOfWeeks'] = ["$numberOfWeeks"];
    return $result;
});

7th January, 2018

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

@adnan483 that's because you can't connect to your database. make sure you are using correct DB_USERNAME=your-mysql-username and DB_PASSWORD=your-mysql-password in your .env file then run:

php artisan config:cache && php artisan route:cache

now point to the route, it will backup your database

BezhanSalleh left a reply on Carbon Get Count Of Weeks In Month • 1 week ago

if you just wanna know what is the current week of the month then as @bobbybouwmann said use weekOfMonth. if you wanna get total number of weeks in a month then you need to create a function to calculate that because it's always almost not a whole number except for February.


public function weeksInMonth($numOfDaysInMonth)//totally upto you, what to pass
{
    $daysInWeek = 7;
    $result = $daysInMonth/$daysInWeek;
    $numberOfFullWeeks = floor($result);
    $numberOfRemaningDays = ($result - $numberOfFullWeeks)*7;
    return 'Weeks: '.$numberOfFullWeeks.' -  Days: '.$numberOfRemaningDays;
}

$numberOfDaysInMonth= Carbon\Carbon::now()->daysInMonth;
$this->weeksInMonth($numberOfDaysInMonth);
Weeks: 4 - Days: 3  //for Jan
if you just want the weeks then just return that.

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

@adnan483

Route::get('/backup_database', function(){
    \Artisan::call('backup:mysql-dump');
    return 'database backed up';
});

the problem might how you are making the request... try the above snippet, check your storage/app/yourdb_timestamp.sql file. and then see where and what is not working in your code... you haven't posted your route or how you are trying to get the backup...

BezhanSalleh left a reply on Backup Doesn't Work • 1 week ago

what does it show, error or anything?

6th January, 2018

BezhanSalleh left a reply on Connection To Controller Isn't Working • 1 week ago

buddy your code snippet works just fine, just add the following in your lessons directory's index view.

@if (session("success"))
    <div class="alert alert-success">
        {{session("success)}}
    </div>
@endif 
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.