m7vm7v

m7vm7v

Member Since 3 Years Ago

Liverool

Developer at Manchester

Experience Points 152,500
Experience Level 31

2,500 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 1366
Lessons
Completed
Best Reply Awards 21
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.

09 Feb
5 months ago

m7vm7v left a reply on Trying To Get Property Of Non-object In Riari Laravel Forum

I have not used this pack before so please ignore me if my answer is incorrect but you can try -

@if($thread->lastPost)
    {{ $thread->lastPost->author_id }}
@endif

m7vm7v left a reply on Better Way Of Getting Posts By Some Params

From both the examples the second approach looks better. Rather the !is_null($request->input('type')) you cane use $request->has('type') and inline the statements for some refactoring.

01 Feb
5 months ago

m7vm7v left a reply on One Auth For Multiple User

Hi, you can use https://github.com/spatie/laravel-permission so then you will be having single login interface and multi roles easily.

m7vm7v left a reply on Queue Crash After Upgrading From 5.6 To 5.7

It looks like a known problem https://github.com/symfony/symfony/issues/20988

Have you tried executing sudo phpdismod opcache after so try restarting all the dependencies.

I hope that helps you.

m7vm7v left a reply on Constant Expression Contains Invalid Operations And Expression Is Not Allowed As Default Value Errors

You can use sometimes and when you validate if the email is the same then do not include it in the request https://laravel.com/docs/5.7/validation#conditionally-adding-rules

30 Dec
6 months ago

m7vm7v left a reply on Laravel Check Nullable

If the object extends Model then you can call the ->exists() when you retrieve the object that returns true/false.

m7vm7v left a reply on Localization Series

+1 Nice suggestion @cryptopia I would love to see such a series.

m7vm7v left a reply on Return A Model With Dynamic Eager Loading

I would highly recommend you not to use the env() directly in your code -> better if you store this in your configuration files and use the config(). Other than that eager loading as you have found out comes with the ->with().

01 Dec
7 months ago

m7vm7v left a reply on Filling Fields On Input

Fair enough @bigstack2. You could write your relationship between City & Country so then-

public function yourMethodSendingDataToTheView()
{
    //some validation ...

    $city = City::whereName(request('searchinput'))->with('country')->firstOrFail();

    return view('your_view', [
        'data' => $someData,
        'city'  => $city->id,
        'country' => $city->country->id,
    ]);
}

so then in your view you would be able to use the {{ $city }} and {{ $country }}

m7vm7v left a reply on Search Multiple Tables And Columns From Database

@ralphdns there might be someone else running into the same issue. Could you possibly write down what was your solution so this thread could be actually helpful.

m7vm7v left a reply on How To Make Default Auth Use Redis Queues?

You could rewrite/extend the ResetPasswordController adding the - reset(Request $request){...} and store your logic there extending it to use Queue just explore how the Trait is using the broker and the reset() method in trait ResetsPasswords

m7vm7v left a reply on How Can I Add Watermark On Video

It depends what libraries are you using.

I would suggest to use some js library such as https://www.npmjs.com/package/videojs-watermark or https://github.com/xbgmsharp/videojs-watermark

Or simply edit the video with your watermark and use the video as it is.

m7vm7v left a reply on Filling Fields On Input

I might have misunderstood you question at first then. If you need to do some logic behind then just do it in your controller. The html form you have given I would assume is part of an view. Got to the method that calls that view (your controller) and then you could have something like -

public function yourMethodSendingDataToTheView()
{
    //some validation ...
    
    $city         = City::find(request('city'));
    $country = Country::find(request('country'));

    $matching = false;

    if($city->name === request('searchinput')) {
        $matching = true;
    }

    return view('your_view', [
        'data'          => $someData,
        'city'            => $city,
        'country'    => $country,
        'matching' => $matching,
    ]);
}
30 Nov
7 months ago

m7vm7v left a reply on Filling Fields On Input

On the second attribute where you have null you can set a prefilled value such as {{ request('country') ?? null }}

m7vm7v left a reply on Validate JSON With FormRequests

You can create a custom validation rule https://laravel.com/docs/5.7/validation#custom-validation-rules

so then the in the rules() you can do something like -

    public function rules()
    {
        return [
            'post' => ['required', 'json', new ValidateJsonPost], //or ValidatePostFromJson ...
    ];
    }

then create it php artisan make:rule ValidateJsonPost

    public function passes($attribute, $value)
    {
        //json decode the $value
    //then Validator::make($decodedJson, [
        'title' => 'required|min:5|max:100'
    ])
    }

There are a few other ways but for me that looks the cleanest approach. Hope that helps.

19 Nov
8 months ago

m7vm7v left a reply on How To Show JSON Response When We Hit Logout Method In Api?

In your logout() method you could have an

if( auth()->guest() ) {
    return response()->json([
    'name' => 'Name',
    ]);
}

m7vm7v left a reply on How To Display Specific Column Value In Collection Laravel

In your controller you could filter the collection

$seekers=User::orderBy('created_at','desc')->where('is_accepted', '=', '0')
->with(['education','language', 'certification','skillset','experience','career','project'])
->filter(function ($user) {
    return $user->education->course_or_board == 'PG';
});

or in your view you could have an if statement

@foreach($seeker->education as $edu)
    @if($edu->course_or_board == 'PG')
        {{ $edu->course_or_board}}
    @endif
@endforeach

m7vm7v left a reply on Error When I Try To Use Json Translation File In My Package ?

Hi @cherrypulp

I am not sure if I understand it correct but are you trying to override a laravel core functionality.

In the documentation - https://laravel.com/docs/5.7/localization you can find out that the lang file should be a php file returning an array with values.

I do not think you are able to change this to be using json. Anyone correct me if I am wrong.

So basically in your lang file you have to do - myfile.php

<?php

return [
    'users' => 'Users'
];

so then you could use the __('myfile.users'); or @lang('myfile.users') to retrieve it

18 Nov
8 months ago

m7vm7v left a reply on Error When I Try To Use Json Translation File In My Package ?

I would recommend you using more of the dd(); helper.

If you do dd(__DIR__); it would easily stands out where you are currently at.

Anyway even if the official docs recommend you using the __DIR__ you could also try the resource_path('lang') - https://laravel.com/docs/5.7/helpers#paths

m7vm7v left a reply on Problem With Join Tables

I would recommend you to change of using Models + relationships.

It does not mean you are doing it wrong but would make your life easier.

In your User model you could have -

public function profile()
{
    return $this->hasOne(Profile::class);
}

public function clicks()
{
    return $this->hasManyThrough(Click::class, Profile::class);
}

public function impressions()
{
    return $this->hasManyThrough(Impression::class, Profile::class)
}

then in your controller

public function index()
{
    $data = auth()->user()->with(['profile', 'clicks', 'impressions']);
}

m7vm7v left a reply on Search Multiple Tables And Columns From Database

Hmm you have missed the name="location_id" parameter on the second <select> then in your [email protected] you would have the

    public function getIndex( Request $request ) {
        //validate the request 

    $demand_id = $request->input('demand_id');
    $location_id = $request->input('location_id');
        
        // Query and paginate result using the values from demand_id & location_id

    // return;
    }

m7vm7v left a reply on Select In Blade

Try with

<select>
  <option value="1" {{ $bill->payment_id == 1 ? 'selected ' : ' ' }}>Rimessa diretta</option>
  <option value="2" {{ $bill->payment_id == 1 ? 'selected ' : ' ' }}>Bonifico Bancario</option>
  <option value="3" {{ $bill->payment_id == 1 ? 'selected ' : ' ' }}> PayPal </option>
</select>

m7vm7v left a reply on Laravel Helper Function

You could do in your Post model -

public function isArchived()
{
    return $this->archived == 1;
}

and in the blade you could have simply the

@foreach(auth()->user->posts as $post)
    @if($post->isArchived())
        //some logic for the archived posts
    @endif
@endforeach
13 Nov
8 months ago

m7vm7v left a reply on Notify On New Connection From New Device

@dlebedef You can extend that table as much as you would like.

What I would suggest is to look after like two factor authentication, this one looks like a good one to help you with. Hope the link is not considered against the rules. https://scotch.io/tutorials/how-to-add-googles-two-factor-authentication-to-laravel

12 Nov
8 months ago

m7vm7v left a reply on Notify On New Connection From New Device

@dlebedef so then you could easily create a new table with trusted_devices and a pivot table between the records and the users so then the user could have a hasMany relationship with the trusted_devices so then in the middleware you could check against this table.

m7vm7v left a reply on Implementing Laravel Redis, Echo And Vue.js For Real Time Update

Could you possibly give us some code that we can amend so we can help you with your issue.

You would really benefit of watching these series https://laracasts.com/series/get-real-with-laravel-echo

m7vm7v left a reply on Laravel 5.7 Email Verification

In my opinion the middleware approach is the ideal in this case.

Like Jeffrey says - think that the middleware is like and onion layer. The email verification is a protection that would be the best to be handled trough that onion so the request would continue or stop execution early rather than hitting controller or a policy - which is not incorrect but would make more sense that can be handled in the request level by the middleware.

m7vm7v left a reply on Notify On New Connection From New Device

I had to do something similar before. What I did then was creating a new middleware that is checking the logged user's fields ("browser", "platform" and "device") and check them against the current request.

If is something else then update the user's data and flash the message (or additional action) and return the $next object as usual. Do not forget to register the new middleware to be executed on all requests.

Hope that helps you.

m7vm7v left a reply on How To Customize Delete Functionality On Nova?

You could define a new Action.

php artisan nova:action DeleteModel so then in the handle method you could add the delete action

public function handle(ActionFields $fields, Collection $models)
{
    foreach($models as $model){
        $model->delete(); //->softDelete()
    }

    return Action::message('Deleted!');
}

In the nova Model add the new DeleteModel action in the actions() method.

Do not forget to remove the delete button from the default actions.

so then if you need for this action some additional information you could add this in the fields() method in the DeleteModel.

Have a look at this video - https://laracasts.com/series/laravel-nova-mastery/episodes/10

m7vm7v left a reply on Validation Auth And Functional Test In One Method?

It is a personal preferences in the end of the day.

What I would do is following what Jeffrey has shown us in the TDD lessons. I would separate the test into smaller more easily understandable-readable tests. For example if I have 2 fields that need validation I would create 2 tests for each a_post_requires_a_title so after once tested this then in the an_authenticated_user_can_create_new_forum_post you do will just send a validation friendly data as you already know it is fine.

Smaller test - better readability, easier to understand if you go again in 6 months fo a change or someone else picks it, and then if a functionality is changed then only the small piece of test would be amended rather than going trough the big test - for example later on the client decides that the title is not only required as you have tested in a_post_requires_a_title but also it needs atleast 20 chars - then you would go to the 'big' test and amend it rather than just creating additional small test for the or amending the a_post_requires_a_title with a better title of course.

When you separate the big test into smaller then you will find out that all the comments you have placed could be actually removed entirely as that will be explained in the test name itself.

In addition try creating some helper functions.

Hope that helps.

m7vm7v left a reply on Policies/Gates For Custom Things?

You could easily do that inside your LessonPolicy -

public function seeInvoiceWithFailedChargingAction(User $user, Lesson $lesson)
{
    if ( lesson has invoice, and invoice was attempted to be charged but failed) { 
        return true;
    }

    return false;
}

Then you can use @can('seeInvoiceWithFailedChargingAction', $lesson)

Hope that helps and guide you in the right direction.

09 Nov
8 months ago

m7vm7v left a reply on How Do I Test Login Throttling?

What I would do is for example if you have throttled for 5 times then

//create a user with known password 
$user = factory(User::class, ['email' => '[email protected]', 'password' => 'secret']);

//then make 5 post request to the authentication route
for ($i = 0; $i < 5; ++$i) {
        $this->post(route('admin.authenticate'), [
            'email' => $user->email,
            'password' => 'wrong',
        ]);

    $this->assertStatus(422);
}

//then on the 6th you would expect to see the throtteler to stop the request
$this->post(route('admin.authenticate'), [
            'email' => $user->email,
            'password' => 'wrong',
]);

$this->assertStatus(429);

I would also recommend you to watch this https://laracasts.com/series/whats-new-in-laravel-5-5/episodes/17 and use the $this->whithoutExceptionHandling();

m7vm7v started a new conversation Looking For The PHPStorm Selection Keybinding

What is the default keybinding for selecting a higher instance on Mac? For example if I have the line someFunction($array = ['something' => 'else']) and my pointer is on the word else when I press this combination I expect the 'else' to be selected if I press it again ['something' => 'else'] will be, if once again then $array = ['something' => 'else'] and so on.

20 Oct
9 months ago

m7vm7v left a reply on Role Question - Shall I Set The Access In Router Or Controller Or Both?

The same as before - just stick with a convention you would like to use and maintain it.

What here in Laracast has been advised is to try as best as you can to stick with 1 'resource' controller with all the methods and if you need to extend some functionality then create a new one with the logic for it. For example getImages() getSmallerImages() getBiggestImages() getBlackAndWhiteImages() could easily be in a new controller 'ImagesController' with index(){ $image->bySize('big')} and create some logic behind for a big/small images in the Model. I would have 1 controller instead of the 4 you have given as an example and rely on get parameters site.dev/posts/1/images?size=big&blackAndWhite=true then the controller could validate, authorise, get data and return as json/view - but getting the data I would store in the Model itself.

Hope that makes sense.

17 Oct
9 months ago

m7vm7v left a reply on Role Question - Shall I Set The Access In Router Or Controller Or Both?

The simple answer would be - Yes, the route middleware would be enough.

But consider the situation when you need both. What if in the middleware you specify that admin and moderator can visit the controller's method but in the controller you could make a different logic depending who is visiting.

public function viewIndex(){ 

    if(is_admin){
        return view('view_with_administration_panel_and_moderator_panel')
    }

    if(is_moderator){
        return view('view_with_moderator_panel_only')
    }
}

What I would advice you is to use whatever makes more sense to you.

I would use Policies and authorisation rather than route middleware or a bunch of if_else statements in the controller. In the controller you would just simply have $this->authorize('view', $post); OR route ->middleware('can:view,App\Post'); Have a good look at https://laravel.com/docs/5.7/authorization#writing-policies Hope that helps you.

29 Sep
9 months ago

m7vm7v left a reply on Help BelongsToMany And HasMany

Not sure is it that what you are asking for but have you tried the hasManyTrough relationship - https://laravel.com/docs/5.7/eloquent-relationships#has-many-through

    public function items()
    {
        return $this->hasManyThrough('App\Item', 'App\Home');
    }

I hope that will help you.

m7vm7v left a reply on Allowed Memory Size Of 134217728 Bytes Exhausted (tried To Allocate 65015808 Bytes)

You can try this one to guide you of what you need -

        $adModels = RevAdvertisement::select('id', 'type', 'link', 'banner', 'country', 'city', 'post_code')
            ->where('user_id', '<>', $userId)
            ->where(['status' => 1, 'payment_status' => 1]);

        if($userCountryId!==null)
            $adModels->where('country',$userCountryId);

        $adModels = $adModels->get()->map(function ($adModel) {
            if($adModel->type == 'Youtube'){
                $adModel->link = $adModel->link . '?autoplay=1&origin=https://www.xyz.vip';
            }

            return $adModel;
        });

        dd($adModels);
23 Sep
10 months ago

m7vm7v left a reply on Error: Call To Undefined Method App\User::users() -- Trying To Differentiate Users

You better try using Policies. Its really easy and makes a lot more sense at then and of the day.

for the isAdmin() method I would suggest is to change it for the current user, as the logic follows this, buts its all up to you

public function isAdmin()
    {
            if ($this->role == 1)
            {
                return true;
            }

        return false;
    }

what you are trying here is most likely to be called differently -

public static function getAdmins()
{
    return self::where('role', 1)->get();
}

in the blade I would suggest to make a second check

@if (auth()->check() && auth()->user()->isAdmin())

Hope that all makes sense.

20 Sep
10 months ago

m7vm7v left a reply on Should Caching Be Done Within A Repository?

You can extract the caching on a different level. What I can suggest you is creating an interface ForumRepositoryInterface which will implement the methods that any repo should have -

interface ForumRepositoryInterface {
    public function getAll();

    public function store();

    ....
}

Then create your repository - DbForumRepository

class DbForumRepository implements ForumRepositoryInterface {

    public function getAll()
    {
        return Forum::all();
    }

    public function store()
    {
        return Forum::create([
            'title'   => request()->title,
            'body'    => request()->body,
            'user_id' => auth()->id(),
        ]);
    }
}

Then the caching -

use Illuminate\Contracts\Cache\Repository as Cache;

class CachingForumRepository implements ForumRepositoryInterface {

    private $cache;

    private $repository;

    public function __construct(ForumRepositoryInterface $repository, Cache $cache)
    {
        $this->repository = $repository;
        $this->cache = $cache;
    }

    public function getAll()
    {
        return \Cache::rememberForever('forum', function (){
            return $this->repository->getAll();
        });
    }

    public function store()
    {
        $forum = $this->repository->store();

        \Cache::delete('forum');

        return $forum;
    }
}

Then go to your AppServiceProvider to register them -

public function register()
    {
        app()->singleton(ForumRepositoryInterface::class, function () {
            $dbRepo = new DbForumRepository();

            return new CachingForumRepository($dbRepo, app('cache.store'));
        });
    }

I hope that makes sense and helps you to understand the principles.

m7vm7v left a reply on Creating Brand Categories

You need to make a few tweaks

public function index(Channel $channel)
{
        if ($channel->exists) {
            $brands = $channel->brands()->latest();
        } else {
            $brands = Brand::latest();
        }

        return view('brands.index', ['brands' => $brands->paginate(15)]);
}

And in you view -

<div class="container">
    @foreach ($brands as $brand)
        @if($brand->channel_id == 1)
        //do something
    @endif
        @if($brand->channel_id == 2)
        //do something
    @endif
    @endforeach
</div>

{{ $brands->links() }}

Have a good read at https://laravel.com/docs/5.7/pagination

16 Sep
10 months ago

m7vm7v left a reply on Missing

Hi @fam , if you think that is the answer that helped you the most to solve the problem could you possibly click the 'tick' under the avatar as it could help someone else who has run into the same issue?

m7vm7v left a reply on Failed To Load Css And Js Files

Is it the case you are migrating to a different OS? What was the OS on the PC and whats on the laptop? If you could use a vagrant/docker box would suit you the best in such a cases.

m7vm7v left a reply on REST Authentication

Hi, I would recommend you to use Laravel Passport - it is what you need for this task. Just follow the official instruction as they are clear enough - https://laravel.com/docs/5.7/passport

m7vm7v left a reply on Best Way To Authorize

I would say that the using Policies would be a good option and the best place I would store would be in the beginning of the controller's method. I think that would give you the best flexibility and in the end of the day you can use 'can()' in the blades and will give a good control in place.

m7vm7v left a reply on Laravel5.6: Php Artisan Migrate --path Is Not Working

Check your migrations table in the database. You might have already executed them and meaning there will be 'Nothing to migrate'. Remember that if once executed the migrations have to be reverted/executed after if you have changed something. If already in production then write a new migration and describe only the additional information. Hope that makes sense. Just for debugging you could try to copy and paste all in the root migrations folder and migrate it to see if they are executable.

m7vm7v left a reply on Change Files In Vendor

I know there is a good answer already but it would worth to mention that there is another option which is really reliable -

Create a patch and apply it with composer -

https://www.devroom.io/2009/10/26/how-to-create-and-apply-a-patch-with-git/ https://punkt.de/en/blog/2017/patches-with-composer.html

m7vm7v left a reply on How To Setup Laravel Task Shedule On Windows 7 With Localhost WAMP

Have a good look at this article - https://laracasts.com/discuss/channels/general-discussion/running-schedulerun-on-windows

I would highly recommend you to use Vagrant or Docker - once you run your project in a box then you will make your life much easyer.

m7vm7v left a reply on Laravel5.6: Php Artisan Migrate --path Is Not Working

Try with php artisan migrate --path="database/migrations/ef"

m7vm7v left a reply on Missing

try swapping the

{!! Form::open(['method'=>'PATCH','route'=>'post.update']) !!}

with

{!! Form::open(['method'=>'PATCH','route'=>['post.update', $edit->id]]) !!}