LozovoyV

LozovoyV

Member Since 3 Years Ago

Saint-Petersburg

Experience Points
8,270
Total
Experience

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-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] 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 2
8,270 XP
03 Jun
2 years ago

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

Try

stepId = variable;

$.ajax({
    type: 'DELETE',
    url: '{{ URL::route('steps.destroy') }}/'+stepId,
    data: {
        '_token': $('input[name=_token]').val(),
    },
});

but I still can't understand what is your Route::get (or post?) looks like

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);
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 can override '__get()' magic method or make method for getting value

class Report extends Model
...
public function fieldValue($fieldName)
{
  return $this->bla->bla->value($fieldName)
}

and use {{$report->fieldValue('a')}}

29 Mar
2 years ago

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

@horizone 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

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.

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.

What your 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 are reading config
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

// here we are geting 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 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('item_has_items', function (Blueprint $table) {
            $table->integer('id');
            $table->integer('parent_id');
        });

And make relation

namespace App;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{

public function children()
{
return $this->belongsToMany('App\Item', 'item_has_items', 'parent_id', 'id');
}

public function parent()
{
return $this->belongsToMany('App\Item', 'item_has_items', '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');
  }

$item->children will return collection of items with parent_id equal to $item->id. $item->parent will return item with id equal to $item->parent_id

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

This way you must define it in model class to access it at model instance like $page->classSelector, if you mean this. 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 AJAX and authentication through Passport. 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? Upd. Session is set and works in not API calls

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. Constructor called before middleware loads session, guards and e.t.c. Try to dd(auth()->user());

And try this:

public function __construct()
  {
    $this->middleware(function ($request, $next) {
      if (auth()->user()->is_admin)
        $this->user = User::find(session('client_id'));
      else
        $this->user = auth()->user();
      return $next($request);
     });

 }
27 Sep
2 years ago

LozovoyV left a reply on Add Custom Function To Auth Facade

@Dreamer I didn't try 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,
    ...

May be you will have to change namespaces. 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\User
     */

    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
3 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. UPD. Oops. No. I'm going to sorcecode... =)

LozovoyV left a reply on HasManyThrough Problems With SoftDeletes

@InaniELHoussain did you try another relaton model: $patient->operations()->withTrashed()->payments() ? As I can understand only operatin has softdelete and you want to retrieve them with payments?

LozovoyV left a reply on Sending Bulk Email In Laravel, The Best Way

@maxnb how and where are you store email adressess of your subscribers?

LozovoyV left a reply on Laravel 5.2 Overwrite Registration

@Sven0188, you are on correct way. Overriding functions is normal case. Just do it not in vendor folder. When you run composer update you might lose your changes. You have app\Http\Controllers\Auth\AuthController.php where you can redeclarate function showRegistrationForm(), pass all data you need to view and change view file as you like