Borisu

Borisu

Member Since 2 Years Ago

Experience Points 131,020
Experience Level 27

3,980 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 866
Lessons
Completed
Best Reply Awards 64
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.

18 Mar
3 months ago

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@SPL3S - Ok, there are a couple of issues with the code.

  1. Try to avoid calls to all() since it's potentially querying huge amounts of data. Instead use some kind of filtering or paging.
  2. You are trying to instantiate $clubInfo in the show() method of the controller, but it is never passed into the route as a parameter, neither is the $athlete for that matter. Rewrite it to only receive the $event:
public function show(Event $event)
{
    //
}
  1. Use this event to get the associated club info, user, judges etc.
public function show(Event $event)
{
    // all of these should be existing relationships on the event
    $clubInfo = $event->clubInfo;
    $clubJudges = $event->clubJudges;
    $athletes = $event->athletes;
    ...
    
}
  1. The final thing to note is that since this route will only work if there is an existing event, you won't be able to use it for both creating and editing. You'll have to define another route for creating a new event. (This is because your route is trying to find an event id specified by the route parameter {event} and it will just fail if none exists.

I'd suggest you stick to the RESTful routes: [GET] index, [GET] show, [GET] create, [POST] store, [GET] edit [PATCH] update, [DELETE] destroy

14 Mar
3 months ago

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@SPL3S - Can you tell me the column names of the table, the route you're accessing and the variables you pass through the controller?

Borisu left a reply on Query Builder + Where + Inner Select

@RAJCSANYIZ - Probably the date field wasn't getting selected properly and now that you're using whereDate it's fine.

Borisu left a reply on Modify Headers Before Authentication

You have to set the header on the request:

public function handle($request, Closure $next)
{
    if ($request->cookie('token')) {  // probably also a good idea...
        $request->headers->set('Authorization', 'Bearer ' . $request->cookie('token'));
    }

        return $next($request);
}

Borisu left a reply on Query Builder + Where + Inner Select

The question is what are you exactly trying to do? Just by reading the query I gather you want to select tms.id, tms.dayoff, tms.user_id and just extract the last tms.id (max in the subquery). If this is correct you can just take the latest record in eloquent:

$q = MonthlyStats::whereDate('stat_date', '2019-03-01')->latest()->first(['id', 'dayoff', 'user_id']);

MonthlyStats is the Eloquent model associated with the table tmteher_monthly_stats.

11 Mar
3 months ago

Borisu left a reply on Testing Notifications

I would just do an "outside-in" test.

// when the user selects to be notified
// and that notification should be sent weekly
// assert that the db has a notification (of certain type) scheduled to run weekly

This way you avoid seeding the database with notifications and concentrate on the functionality.

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

@SPL3S - The series is "Build a Laravel app with TDD".

In your template you can check if there is a record for the club_info:

@if (auth()->user()->club_info)
    // display the form for editing
@else 
    // display the form for entering
@endif

Having said that, you might try to just change the method with the @if and use the input value field to insert any existing data:

<input type="text" value="{{ optional(auth()->user()->club_info)->name }}" placeholder="Enter a club name">

This way if there is a club the user will see the value, otherwise they'll see the placeholder text.

The optional() helper just protects you from calling a property on null (if the user has no club_info, then it'll be null)

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

You can use a @include directive to just insert another template, similar to what Jeffrey did in the last series with the activities. What I don't understand is why you're using a @foreach when users can have only one clubinfo? Maybe I'm not getting it right.

08 Mar
3 months ago

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

Then you want to check that the user has no clubs:

<form method="POST" action="/same/url/for/both/methods">
@if(auth()->user()->clubs)
    @method('PATCH')
@endif
    <input>
    // etc.
</form>

Borisu left a reply on Hide Submit Form When Data Present In DB & Show Update Form

Just move the creation form out of the @if block. This way it will always display. I would personally move it to the top, so it's easy to create a new entry without scrolling like crazy whenever you get to have many rows in the db. Something like:

<table class="table">
    <thead>
        <tr>
            <th scope="col">
                Club Name!!
            </th>
            <th scope="col">
                Country
            </th>
            <th scope="col">
                City
            </th>
            <th scope="col">
                Head Of delegation
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <form action="/events/{{ $event->id }}/club-info" method="POST">
                @csrf
                <td>
                    <div class="form-group">
                        <input class="form-control" name="club_name" required="" type="text" value="{{ old('club_country') }}">
                    </div>
                </td>
                <td>
                    <div class="form-group">
                        <input class="form-control" name="club_country" required="" type="text" value="{{ old('club_country') }}">
                    </div>
                </td>
                <td>
                    <div class="form-group">
                        <input class="form-control" name="club_city" required="" type="text" value="{{ old('club_city') }}">
                    </div>
                </td>
                <td>
                    <div class="form-group">
                        <input class="form-control" name="club_head_of_delegation" required="" type="text" value="{{ old('club_head_of_delegation') }}">
                    </div>
                </td>
                <td>
                    <div class="form-group">
                        <button class="btn btn-primary" style="cursor:pointer" type="submit">
                            Save
                        </button>
                    </div>
                </td>
            </form>
        </tr>
        @foreach($event->clubInfos as $clubInfo)
            <tr>
                ...
            </tr>
        @endforeach
    </tbody>
</table>

The foreach will display nothing if there is no data, so no need to explicitly check the count.

14 Feb
4 months ago

Borisu left a reply on Pagination Without Eloquent

You can use the Paginator class. Something like this:

$slicedCrashes = array_slice($crashes, (request('page') ? request('page') - 1 : 0) * $perPage, $perPage);
return new LengthAwarePaginator(
            $slicedCrashes,
            count($crashes),
            $perPage,
            request('page'),
            ['path' => url()->current()]
        );

LengthAwarePaginator accepts the result subset (slicedCrashes), the total count, the amount of results per page, the current page, and an array of options. In the options array you only have to make sure that the url is correct, in order to build the links correctly. Then you can use the results as a normal paged Eloquent model.

11 Feb
4 months ago

Borisu left a reply on Calling A Laravel Blade Template Function In Php

This is because you assigned a string to success. Whenever you open a php block, the mustache syntax doesn't apply anymore. To fix that:

<?php
    $success = route('payment.success');
?>

This is unnecessary, because you can just output it like this:

<input ...>
{{ route('payment.success') }}
07 Feb
4 months ago

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

@DRONAX - Do you allow for guests to comment? In my opinion you shouldn't, then you'll always have access to the user id. (What does this form actually contain?)

Anyway I think we're getting side tracked. The Vue question has been answered.

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

@DRONAX - I think it's best to make a custom rule: php artisan make:rule OnceDaily. Then put the validation logic and error message inside that class:

class OnceDaily implements Rule
{
    public function __construct(Shop $shop)
    {
        $this->shop = $shop;
    }

    public function passes($attribute, $value)
    {
        $lastComment = Review::where('created_at', '>', now()->subHours(24))
            ->where('shop_id', $this->shop->id)
            ->where('email', $value)
            ->orWhere('user_id', auth()->id())
            ->latest()
            ->first();
        return $lastComment == null;
    }
}

Calling it in the controller would be like this:

$request->validate([
    'body' => 'string|min:10',
    'type' => 'integer',
    'email' => ['required', new OnceDaily($shop)]
]);

Since you didn't provide context to the last piece of code I didn't know exactly how to form it, but hopefully you get the idea.

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

@DRONAX - I believe you can use the unique rule for that, or do you want to disallow consecutive comments by the same user?

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

@DRONAX - For Laravel 5.7 you can assign the validated field to $attributes, otherwise you'll have to do it manually.

In your controller:

public function store()
{
    $attributes = request()->validate([
        'field' => 'rules',
        'other_field' => 'rules'
    ]);
    // other code
}

If this call to validation() fails Laravel will redirect back to the original page with an error response. That's where you use the first solution I showed you.

.catch({response: {data: {errros: err = ''}}} => {
    for (let field of Object.keys(err)) {
        this.flash(err[field][0], 'error');
    }
});

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

@DRONAX - When you make a custom json response you can just flash the destructured object:

.catch({response: {data: {errros: err = ''}}} => {
    this.flash(err);
});

I would instead use the request()->validate() method, which will return json automatically (for ajax calls) and loop over all errors in vue, but that's just me.

06 Feb
4 months ago

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

You can iterate over the error.response.data and flash a message for each error:

.catch(error => {
    let errors = error.response.data.errors;
    for (let field of Object.keys(errors)) {
        this.flash(errors[field][0], 'error');
    }
});

Borisu left a reply on Promise This Context

You can bind this to the resolve call: resolve(response).bind(this). That should be enough. Actually you can bind any object.

Borisu left a reply on Display Validation And Custom Errors Laravel In Vuejs

Hi,

error.response.data is an array/object of all the errors on the page. You'll have to iterate over it and then display the errors. That's why you're seeing [Object object], because when you console.log an object that's it's string representation.

19 Nov
7 months ago

Borisu left a reply on Show And Hide Arrow Using JS

Yes, you haven't closed the outermost curly brace and the parenthesis. Your IIFE is also not invoked.

06 Nov
7 months ago

Borisu left a reply on Edit Many To Many With Two Foreach?

You don't need the outermost loop. Just call the inner one:

@foreach($genres as $genre)
    <option {{ in_array($genre->id, $movie->genres->pluck('id')) ? 'selected' : '' }} value="{{ $genre->id }}"> {{ $genre->title }} </option>
@endforeach

Borisu left a reply on Laravel Job Is In The Jobs Table But Not Dispatching

Did you run php artisan queue:listen in the console?

Borisu left a reply on Auto Incremented Number Like: 0001

You could keep the normal integer increment and just display it differently:

// in your blade files
{{ str_pad($number, 4, '0', STR_PAD_LEFT) }}
05 Nov
7 months ago

Borisu left a reply on Conditional Logic

There are many ways to move away from repetition like this. You could just add the paths of the files to an array and do a foreach and delete. Or you could use the strategy pattern (watch about it in the 'Whip monstrous code into shape' series https://laracasts.com/series/whip-monstrous-code-into-shape).

Borisu left a reply on How To Run Controller Only From Intern

In your routes file you can assign the 'auth' middleware. This will force users to login before they can use the service.

For example:

Route::get('/distance/{coordinates}', '[email protected]')->middleware('auth');

Alternatively you can make your own middleware to handle requests to that endpoint.

Another thing you can do is limit the route via nginx or apache, by allowing only local ips to access it.

Borisu left a reply on Vue Warn Error In Render: "TypeError: Cannot Read Property 'link' Of Undefined"

I'm not sure, but I think if you just call notification.link it will work. The reason is that you already assigned notifications to the response data in the promise.

Borisu left a reply on Conditional Logic

Well the problem is that if any of the files is missing the check will fail and nothing will be deleted. An easy way to go around that is just do a single check per file and then delete it:

if (Storage::disk('public')->exists('portfolio/'.$portfolio->cover) {
    Storage::disk('public')->delete('portfolio/'.$portfolio->cover);
}

if (...) {
    // delete the next one
}
02 Nov
7 months ago

Borisu left a reply on File Validation

Did you try to comment out the part before the validation? Just in case some weird side-effect is occurring?

Borisu left a reply on Beginner : Passed Var From Controller To A Vue

Hi, you can do this:

Route::get('/', ['as' => 'home', function() {
    return view('home', ['arch' => $arch]); 
}]);
// or
Route::get('/', ['as' => 'home', function() {
    return view('home', compact('arch')); 
}]);

Borisu left a reply on ACL And Controller Sanity Check

Yes I think at this point it's just personal preference. If it feels good for you then by all means do it, there is no wrong way ;)

Borisu left a reply on Laravel Trigger Model Event On Relation Deleting

@kakallatt You can try to put the transferMembers method in the User event.

Borisu left a reply on Check Date Exists

Actually you can use the validation function to check for things like that.

https://laravel.com/docs/5.7/validation#available-validation-rules

If you have a special case you can make your own rule.

Borisu left a reply on ACL And Controller Sanity Check

I can't really judge it, but it seems redundant to use a static variable. It would be just as easy to write

return view('users', ['access' => 'manage_users']);

This way you could do it for every controller method separately.

Borisu left a reply on Calling A JS Command In Two Places On A Page.

You cannot have two elements with the same id. In your case it's the id="navsearch" on the inputs. You'll have to check the API docs for the rest of the setup.

31 Oct
7 months ago

Borisu left a reply on How Do I Pass Users Id To The Modal?

@sucoms just try it the way i told you it works.

Borisu left a reply on Tests Not Generating Id's.

@finchy70 but you did in the code displayed O.o

Borisu left a reply on Cannot Call Custom Job Method Withing Job Itself

@fogley Yeah there's no method exists on the collection class. You can use count which will return zero or more, it's actually what people use. I think the collection class is macroable so you can just extend it and have the method exists ;)

30 Oct
7 months ago

Borisu left a reply on Cannot Call Custom Job Method Withing Job Itself

@fogley Well it's unclear exactly what you did since you posted no code.

Borisu left a reply on Tests Not Generating Id's.

@finchy70 What about the exact error you're getting?

Borisu left a reply on How To Increase Clickable Size In Svg Icon

Just add make the containing element huge and increase the padding of the div until the svg is small and the clickable area huge. This is quick and dirty ;)

Borisu left a reply on How Do I Tie Laravel And Lumen Together?

Generally you can communicate with other services (in your case your Lumen server) via a Http Client. For example you can use GuzzleHttp to make a get, post, delete request to your api.

Then you can just move the DB and logic to the Lumen server and ask for authentication via GuzzleHttp. On the other side you'll store the session if the API responds with true for example. It's fairly complex and unless you have a very good reason to do so, just stick to the basics :)

Borisu left a reply on Tests Not Generating Id's.

Did you define the factories for these classes?

Borisu left a reply on How Do I Pass Users Id To The Modal?

Ah yes I see now. You can try to change the event listener for the click event

$('.remove-button').on('click', function(event){
        var id=$(event.target).data('id');
        $("#deleteModal").modal("show");
        console.log(id);
    });

, to watch the actual button being pressed. That way you call to

$(this).data('id')

will return the currently pressed id.

Borisu left a reply on How Do I Pass Users Id To The Modal?

You can use the auth helper:

auth()->id()

This will give you the id of the current user.

Borisu left a reply on What Is The Difference ?

Short answer is: there's no difference.

Borisu left a reply on Cannot Call Custom Job Method Withing Job Itself

It depends on the context. Can you post your full job class?

29 Oct
7 months ago

Borisu left a reply on I Need To Edit My Invoice But How To Fill Invoice Items In It

@partabsaifzakir yes, if you look at the code I posted it's basically the same ;) Anyway glad you made it work

Borisu left a reply on I Need To Edit My Invoice But How To Fill Invoice Items In It

@partabsaifzakir Well I assumed you had it working with just the backend. Can you check if your ajax calls return valid data?

26 Oct
7 months ago

Borisu left a reply on Laravel 5.7 Databases

@lawkunchi Just an extra thought: You can achieve this with a database view. It will always stay up to date as it is managed at the db level. Then you only need a single migration to initialize the db view.