LozovoyV

LozovoyV

Member Since 2 Years Ago

Saint-Petersburg

Experience Points 8,270
Experience Level 2

1,730 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 24
Lessons
Completed
Best Reply Awards 10
Best Reply
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.

03 Jun
2 years ago

LozovoyV left a reply on Translate Route Url To An Ajax Url

Try

{{ route('steps.destroy', ['step' => $step->id], true) }}

LozovoyV left a reply on Merge Collections

One of things can go wrong here is If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection. What do you see in:

dd($all_deposits, $all_withdrawals);

LozovoyV left a reply on Merge Collections

Try this

$current_user->load('deposits', 'withdraws');

$all_transactions = $current_user->deposits->merge($current_user->withdraws);

dd($all_transactions);
11 May
2 years ago

LozovoyV left a reply on Route Middleware Group Admin Not Working

@syamimhazmi of course, comment return redirect('/'); or use dd() instead of var_dump()

08 May
2 years ago

LozovoyV left a reply on Route Middleware Group Admin Not Working

@syamimhazmi try and see what it prints

    public function handle($request, Closure $next)
    {
    var_dump(request()->user(), request()->user()->isAdmin());

        if ($request()->user() && request()->user()->isAdmin())
        {
            return $next($request);
        }

        return redirect('/');
    }

LozovoyV left a reply on Route Middleware Group Admin Not Working

Try to use

    public function handle($request, Closure $next)
    {
        if ($request()->user() && request()->user()->isAdmin())
        {
            return $next($request);
        }

        return redirect('/');
    }

LozovoyV left a reply on Map Relationship Field To Field On Main Object

You just can override '__get()' magic method

29 Mar
2 years ago

LozovoyV left a reply on How To Only Process And Render A Partial View When Request Is Ajax.

There is another solution ''' View::addNamespace('layout', request()->ajax() ? 'resources/ajaxviews': 'resources/views'); ''' And then ''' @extends('layuot::view') '''

28 Mar
2 years ago

LozovoyV left a reply on How To Only Process And Render A Partial View When Request Is Ajax.

@extends directive works with variables as I found. You can use

@extends($layout)

and pass $layout = 'layuot.app' in non-ajax request and $layout = 'layout.dummy'for ajax. Not sure about empty parameter for @extends but you can try this

LozovoyV left a reply on How To Only Process And Render A Partial View When Request Is Ajax.

Did you try using this?

// controller
    return view('view')->with('is_ajax', $request->ajax());

// view
@if(!$is_ajax)
    @extends('layout.app')
@endif
27 Mar
2 years ago

LozovoyV left a reply on Dynamic Route Problem

You can use

localhost.dev/compare/{versus}

and

public function showVersus($versus)
{
    list($first, $second, $third, $fourth) = explode('-vs-', $versus)
}
02 Mar
2 years ago

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

Already.

Auth::routes();

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

Route::get('password/reset/{token?}', 'Auth\[email protected]');

{token?} means token is not required parameter but optional. So url 'password/reset' runs showLinkRequestForm function. But 'password/reset/token' runs same function.

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

I see it. You have

Route::get('password/reset/{token?}', 'Auth\[email protected]');

And it works fine =) But for password reseting out of the box you must have 4 routes:

// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]');
Route::post('password/email', 'Auth\[email protected]');
Route::get('password/reset/{token}', 'Auth\[email protected]');
Route::post('password/reset', 'Auth\[email protected]');

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

showLinkRequestForm function is defined in ResetsPasswords trait

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

Try to change {token?} to {token} in Route::get('password/reset/{token?}', 'Auth\[email protected]');

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

I ment you have to have this

Route::get('password/reset/{token}', 'Auth\[email protected] ')

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

And what about password_resets table?

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

I mean you have

 GET|HEAD | password/reset/{token}                                                                                          | auth_reset_password_token | [email protected]

Isn't it?

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

Link looks as correct. Ok. Is auth routes out of the box?

LozovoyV left a reply on Reset Password Link From E-mail Not Working.

Show please what you link looks like

01 Mar
2 years ago

LozovoyV left a reply on Where Are You All From?

Saint-Petersburg, Russia

LozovoyV left a reply on Password Resets In 5.4

In views link is generating by route('password.reset') but there is no route with such name. Set ->name('password.reset') to your routes.

28 Feb
2 years ago

LozovoyV left a reply on How Can I Set Auth::routes() With A Dynamic Subdomain

In L5.3 your code works well. In 5.4 it works if in resources/views/auth/login.blade.php override route('auth_login, ['company' => ''])' May be is more simple to register Auth:routes() outside this group?

LozovoyV left a reply on How Can I Set Auth::routes() With A Dynamic Subdomain

Idea is clear. Auth:routes() registers routes with names. For login route name is

GET|HEAD | login | auth_login

In standard views url is generated by route('auth_login'). But you are registering routes in group with parameter, so in this case proper call is route('auth_login', ['company' => 'some_company']). First way is override standard views and methods that use route('auth_login'), second is to play with https://laravel.com/docs/5.4/routing#parameters-optional-parameters

27 Feb
2 years ago

LozovoyV left a reply on Request() Helper Function Not Working In Custom Config File

@jogesh_pi Just look at request() helper function in sources

    function request($key = null, $default = null)
    {
        if (is_null($key)) {
            return app('request');
        }

        if (is_array($key)) {
            return app('request')->only($key);
        }

        return app('request')->input($key, $default);
    }

It uses binded 'request' in app container. In whole application logics:

// here we reads config
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

// here we get request
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

Your app reads config files before it gets request. So using $_SERVER['HTTP_HOST']; is easiest way =) Laravel style is defining global middleware for your purposes

LozovoyV left a reply on Request() Helper Function Not Working In Custom Config File

Is class Request registered in app when you trying to access it in config?

21 Feb
2 years ago

LozovoyV left a reply on Multi Level Heirarchy Relationships

You can create pivot table and use it to make model's relation to itself

Schema::create('pivot_table', function (Blueprint $table) {
            $table->integer('id');
            $table->integer('parent_id');
        });

And make relation

public function children()
{
return $this->belongsToMany('ModelClass', 'pivot_table', 'parent_id', 'id');
}

public function parent()
{
return $this->belongsToMany('ModelClass', 'pivot_table', 'id', 'parent_id');
}

LozovoyV left a reply on Multi Level Heirarchy Relationships

Like this?

public function children()
  {
    return $this->hasMany('ModelClass', 'parent_id', 'id');
  }

public function parent()
  {
    return $this->belongsTo('ModelClass', 'id', 'parent_id');
  }

LozovoyV left a reply on Better Way To Dispaly Button Label Value If I Have An Integer In My DB

Everywhere. Or you can make helper function

function classSelector($state, $enabled, $disabled)
    {
        if ($state)
        {
            return $enabled;
        }
        return $disabled;
    }

LozovoyV left a reply on Better Way To Dispaly Button Label Value If I Have An Integer In My DB

You can use ''' public function classSelector($enabled, $disabled) { if ($this->active) { return $enabled; } return $disabled; } ''' Adn then use it like

<td><span class="label {{$page->classSelector('label-success', 'label-danger')}}">{{ $page->active }}</span></td>

LozovoyV left a reply on NotfoundHttpException For Some Routes

Ouch! Just try to change order =))

Route::get('/information/contact/{slug}', '[email protected]');
Route::get('/information/{slug}', '[email protected]');
01 Feb
2 years ago

LozovoyV left a reply on Route Group With Middleware And Parameters

Do you have any routes in group? =)

LozovoyV left a reply on Route Group With Middleware And Parameters

You can't trace it because you use abort. Try another way

public function handle($request, Closure $next, $role = null /**MvT**/)
    {
       var_dump($role);
       return $next($request);
    }

LozovoyV left a reply on Route Group With Middleware And Parameters

It looks like you assign "middleware" => "acl" without parameter somewere. Try to do this

public function handle($request, Closure $next, $role = null)
{
    dd($role);
}

LozovoyV started a new conversation How To Get User's Session In Passport Authenticated API

In my app I'm using API with authentication through Passport and AJAX. It all works fine. In controller I can get authenticated user, but I can't get user's session. session()->all() returns [] and $request->session()->all() returns Session store not set on request.. How to solve this?

09 Jan
2 years ago

LozovoyV left a reply on Using Middleware In Constructor

@sorcjc I think Trying to get property of non-object In the if line is result of trying to access an empty object: auth()->user()->is_admin. Try to dd(auth()->user());

27 Sep
2 years ago

LozovoyV left a reply on Add Custom Function To Auth Facade

@Dreamer I don't tryed this, but as I can understand you just need to extend Auth facade somethere in your app folder like

<?php
namespace Illuminate\Support\Facades;

use Illuminate\Support\Facades\Auth;

class CustomAuth extends Auth
{
    public static function company()
    {
        return $this->user()->company;
    //I'm not shure, but some like that
    }
}

and change in in your config/app.php

   'aliases' => [
        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        //'Auth' => Illuminate\Support\Facades\Auth::class,
        'Auth' => Illuminate\Support\Facades\CustomAuth::class,
    ...

You can try this and post results, please =)

LozovoyV left a reply on Add Custom Function To Auth Facade

@Dreamer if you want to shorten your code, IMO, it is better to create helper function like this:

if (! function_exists('company'))
{
    function company()
    {
        if(!\Auth::check()) {
            return null;
        }
        return \Auth::user()->company;
    }
}

or, as I used helper function for user()

if (! function_exists('user'))
{
    /**
     * Get an instance of the Auth::user
     *
     * @return App\CMS\Site
     */

    function user($parameter = null)
    {
        if(!\Auth::check()) {
            return null;
        }
        if($parameter) {
            return \Auth::user()->$parameter;
        }
        return \Auth::user();
    }
}

you can just call user('company')

26 Sep
2 years ago

LozovoyV left a reply on Laravel-traslatable From Repository

@Arturo, ouch! May be $category->transalate() must be $category->translate()? =))

25 Sep
2 years ago

LozovoyV left a reply on Laravel-traslatable From Repository

@Arturo did you use Translatable\Translatable trait in your model?

19 Sep
2 years ago

LozovoyV left a reply on HasManyThrough Problems With SoftDeletes

@InaniELHoussain as I understood source code of HasManyThrough there is no way to pass withTrash there.

LozovoyV left a reply on Laravel 5.3 - Sharing $user Variable In All Views

@claus.munch as i have tested \Auth::user() is available after kernel.handled event. You can handel it to share $user. Or just use facade in view. Or make helper function as I listed 2 hours ago

LozovoyV left a reply on HasManyThrough Problems With SoftDeletes

@InaniELHoussain I just opened docs: return $this->hasManyThrough('App\Post', 'App\User');. Is there any difference between return $this->hasManyThrough('App\Payment', 'App\Operation') and $this->hasManyThrough(Payment::class, Operation::class)?

LozovoyV left a reply on HasManyThrough Problems With SoftDeletes

@InaniELHoussain one more idea

return $this->withTrashed()->hasManyThrough(Payment::class, Operation::class);

Try this. May be it will fire