pickab00

pickab00

Member Since 1 Year Ago

Experience Points 9,840
Experience Level 2

160 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 2
Lessons
Completed
Best Reply Awards 0
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.

19 Jun
1 week ago

pickab00 left a reply on Requested An Insecure XMLHttpRequest Endpoint

@SNAPEY - @SNAPEY - Not local. I’m on cloudways hosting and I do not think its behind a proxy. What if it was on proxy? What are the changes I have to make and what could be causing this?

Also I forgot to update on this issue. I have another function similar to this one which does not return this error and returns 404 error with no issues. There is nothing different except I didn’t include the csrf header in that function ajax setup. I tried to do it that way with the function I am having issues with and replicate it the same way as the working one but no luck.

I do not understand why this would happen on some functions while the other has no issues. It is using https while the ajax function with the issue uses http

18 Jun
1 week ago

pickab00 left a reply on Requested An Insecure XMLHttpRequest Endpoint

@SNAPEY - Why is it forcing errors to be displayed on http? My data is on https which I am getting fine but a "on purpose" 404 or 500 error shows the url with http://

pickab00 left a reply on Requested An Insecure XMLHttpRequest Endpoint

@SNAPEY - It returns "failed to load response data". Two are there. Ones status is "canceled" and the other is "blocked:mixed-content". No redirects. Type xhr. The canceled is from jquery.

pickab00 started a new conversation Requested An Insecure XMLHttpRequest Endpoint

I am using ajax to make a request and I do not understand the error. I mean I know what it is But here is my situation.

I am doing an ajax request to fetch some stuff off of the controller and it works fine if there is no error. The requested an insecure XMLHttpRequest endpoint error does not pop up if there is no problem with the response. Here is the Ajax:

function checkFreeMeal() {

    var url_origin   = window.location.origin;

    $('#existing_guest_selector').on('change', function() {

        var guestID = this.value;

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: "GET",
            url: url_origin + '/restaurant-reservations/check-free-meal/' + guestID,

            statusCode: {
                500: function() {
                    $('.something-went-wrong').text('LOOKS LIKE SOMETHING WENT WRONG. CALL IT DEPARTMENT FOR HELP. TELL THEM THIS. STACK TRACE ERROR: FREEMEALCHECK F1X00500');
                }
            },
            success: function(data) {
                if (data == 1){
                    $('.free-meal').prop('checked', true);
                }if(data == 0){
                    $('.free-meal').prop('checked', false);
                }
            }
        });

    });

}

So on existing guest dropdown change, the ID is being passed to the url of ajax along with the url_origin which returns https://domain.com. I am getting the expected result with no problem. But when I select the first item from dropdown (which has the value of null), the server should respond with a 500 error. That is what I am excepting at least. But that is not the case. (Also, the 500 error is caused on purpose and first value of first select item is null on purpose). So my question is, why am I getting the results when an ID is sent over but I am receiving insecure http error when there is an error coming. I am expecting 500 error from controller to the console from ajax but it displays the http insecure error.

pickab00 left a reply on Add A + 1 To WithCount()

@DEANSATCH - Understood. Thank you so much!

pickab00 left a reply on Add A + 1 To WithCount()

@DEANSATCH - Ok so in my example, I used guestpaxes as the relationship name. So it was getGuestpaxesCountAttribute. Which will eventually translate to get guespaxes relationship count using withCount. Correct?

pickab00 left a reply on Add A + 1 To WithCount()

@DEANSATCH - This worked perfectly. In my case it was getGuestpaxesCountAttribute. I do not understand mutators that well. I know what purpose they are for. is the get an attribute to mutators? and is Comments the same as the relationship name? Is Count an attribute to withCount?

Thank you

16 Jun
1 week ago

pickab00 started a new conversation Add A + 1 To WithCount()

I have been using with('relation') and using the count($array->relationship) to get the count of the relationship. But obviously the easier way and cleaner way of doing that is using the withCount(). But the problem is that I am always adding a plus 1 to the count($array->relationship). So like count($array->relationship) + 1. How can I add that within the withCount()?

27 May
4 weeks ago

pickab00 left a reply on Not Able To Access Json

@TYKUS - Just needed to decode to array. Many thanks

26 May
1 month ago

pickab00 started a new conversation Not Able To Access Json

I am outputting an object from a server and json_decode it. Here is the code:

//var $server_settings is from a RESTAPi
$json = json_encode($server_settings);

    return $json;

and the result:

{ settings: { apc.shm_size: "32", character_set_server: "ascii", date.timezone: "", display_errors: "Off", error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT", execution_limit: "60", innodb_buffer_pool_size: "", innodb_lock_wait_timeout: "", key_buffer_size: "", max_connections: "150", max_input_time: "60", max_input_vars: "2500", memory_limit: "128", mod_xdebug: "disable", nginx_http2: "enable", package_versions: { fpm: "enable", mariadb: "", mysql: "5.7", php: "7.3", redis: "" }, short_open_tag: "off", static_cache_expiry: "43200", upload_size: "10", wait_timeout: "" } }

how do I return lets say character_set_server from settings?

25 May
1 month ago

pickab00 left a reply on Need Some Help With Restaurant Menu Management System

@JOHNBRAUN - Hi

Sorry about the late reply. First off, thank you so much for taking the time in doing this. I can't thank you enough. I haven't got time to check this yet. But honestly, I do not think anyone would have taken their time to go this far answering a question. Again, thank you so much! I will get back to you after I am done testing.

But as far as I have read this, this is exactly what I needed and fits the requirements. The explanation was on point. Again. thank you!

20 May
1 month ago

pickab00 started a new conversation Need Some Help With Restaurant Menu Management System

So the idea is pretty basic but I am not sure how it is done or how I should continue with it. Basically I am using laravel as my backend system and I wanted to allow the restaurant managers to add "menu options" to the menu items. when ever they add a new/update a menu item, they will be able to add options. Like if it is large or medium. If he wants pickles or carrots. It can be checkboxes or an input field or radio buttons. There will be many options to choose from. the managers will be adding this from the backend. Now I do not understand how my database would look like. Of course what ever table I create for menu options I will have to link it with the menu items table. That is obvious but how can I tell these things.

  • The category of the menu option. This will be something like, the size. Or the type of meat.
  • The type of option(s). Checkbox or an input field or radio buttons etc (there will be many options to choose from. one menu item may have 2 radio buttons which belongs to meat category and 3 checkboxes which belongs to size or something. It will vary.)
  • Lastly giving them name and id and other nesessary stuff. Also how can I display these (okay this will come later but for now I just want to figure out the db structure and how I could achieve this).

What I was thinking was to have a modal popup which will populate the given information above for the user. So lets say if the user clicked the "add to basket" button, they will be presented with the modal to choose size (maybe a radio button), Amount (which is an input field), extras (which maybe a checkbox). So how can I tell the db that these information/menu options are added in to the db to the specific menu item. What are the tables and relationships?

Thanks a bunch!

10 May
1 month ago

pickab00 left a reply on An In-depth Explanation Of Clear Cache

@JLRDW - Sorry currently I’m on mobile and it gives me 404 if I try on mobile. I always select the best answer (if any). But as soon as I get back on a PC

pickab00 left a reply on An In-depth Explanation Of Clear Cache

@SNAPEY - Thanks Snapey you saved the day once again! This pointed me to the right direction and it works perfectly.

pickab00 started a new conversation An In-depth Explanation Of Clear Cache

Can someone please explain a little in-depth of what clear cache, route, config etc does? I tried searching a lot but I could not find any satisfying answer. What I really want to know is what is view clear. I know it clears compiled view files. But will clearing this force js and css to reload too? If not, how can I force them to be re fetched? Currently I use ?v=1.0 to clear both css and js. But sometimes the user has to close their tab and revisit the page again or do a reload (visiting links does not help) in order to re fetch the new css and js. So that got me thinking if clearing view would help? All I got from the internet so far was that clear view clears complied views. So my question is, will it clear and ask the client to get js and css again too? Will any of the clear commands do what I want to achieve?

09 May
1 month ago

pickab00 left a reply on WithCount() Returns 0

@FTIERSCH - Can't believe I missed that. Thanks!

pickab00 started a new conversation WithCount() Returns 0

$array = $reservation->withCount('guestpaxes')->get();

    //This bit counts the total amount of pax in the query inclusive of guest
    $pax_count = '';

    foreach($array as $count){
        $pax_count = $count->guestpaxes_count;
    }

return $pax_count;

This returns 0 and I am not sure why. I looked at the docs and I am unsure where I went wrong

02 May
1 month ago

pickab00 left a reply on How To Stop Form From Submitting Twice

@FTIERSCH - This seems like the better solution. 429 abort seems to be a good solution but I don’t want the user to be presented with the http error code but rather a simple message bag would do.

Thanks mate

pickab00 left a reply on How To Stop Form From Submitting Twice

@FTIERSCH - Thats a good solution. Can you give me perhaps an idea of where to start from? Thanks a bunch

pickab00 left a reply on How To Stop Form From Submitting Twice

@TUSHAR2004 - This makes more sense. Now it could have been that he tapped the submit button twice thinking it wasn’t being submitted. How can I tackle that if that is the case? I mean pressing the button fast 3 times makes it enter 3 datas. How do I avoid doing that

pickab00 left a reply on How To Stop Form From Submitting Twice

@FTIERSCH - At the moment, I have return redirect back with a message. Shouldn’t that do the same thing as what you have mentioned? Or do I have to redirect to a page other than the form page?

pickab00 started a new conversation How To Stop Form From Submitting Twice

I have an app built from laravel and I hosted it today. One of the users called me today saying that he entered a data twice (with different id's). So there was double entry. The reason for this was that the internet went off while he was filling up the details and he tapped the submit button. Now the 'no internet' error on chrome displayed and once the internet was back up, he refreshed it 3 times and the data was entered 3 times. He thought that he was still on the form filling view so he refreshed 3 times. Now how can I prevent this from happening? Is this possible?

pickab00 left a reply on Jquery Prevent Default Not Working

@TALINON - This was the solution. Sorry I didn’t notice that before. Thanks a bunch. Although I used an alternative. I am calling:

$(‘#form’).unbind.(‘submit’).submit();
01 May
1 month ago

pickab00 started a new conversation Jquery Prevent Default Not Working

So I have a form submission which I am preventing the default. So the code looks something like this.

$("#form").submit(function(e){

var allowSubmit = false;

if (!allowSubmit){
    e.preventDefault();
}

//run something here and say

var a = 1;

if (a != 1) { allowSubmit = false; console.log('failed'); }else{ allowSubmit = true; console.log('works'); }

});

I don't see the problem with this code. The e.preventDefault(); works just fine. But console logs 'works' and it is supposed to set the allowSubmit variable to true correct? Then why is my form not being submitted now that the allowSubmit is true and preventDefault is no longer true?

14 Apr
2 months ago

pickab00 left a reply on Extend Date To 3 More Hours Where Post = Today's Post

@BOBBYBOUWMANN - $start = Carbon::now()->startOfDay()->addHours(3); $end = Carbon::now()->endOfDay()->addHours(3);

This bit is exaactly what I needed. So now I can do this:

$start = Carbon::now()->startOfDay();
$end = Carbon::now()->endOfDay()->addHours(3);

$reservations = Reservation::whereBetween('reservation_made_on', [$start, $end])->get();

So now it will show all the reservations which were made for today and keep them till tomorrow 3AM (bacuse of 3 hours added). But my question is this. Will it collapse with the todays data? I mean if it is 3AM, it will show tomorrows data and todays data right? So is it better to do

$start = Carbon::now()->startOfDay()->addHours(3);
$end = Carbon::now()->endOfDay()->addHours(3);

So that it displays from 3AM to 3AM? So it will not show 2 days data at once (2 days being today and tomorrows) Hope I am making sense here

pickab00 started a new conversation Extend Date To 3 More Hours Where Post = Today's Post

I know the title is a bit confusing. I myself am trying to make sense of it. Basically I am using Carbon to get the posts for today and this is how it looks like.

$array = Reservation::whereDate('reservation_made_on', Carbon::today())->get();

So with this, I am getting the reservations made for today (if any). Now that means that the reservations will not be visible after 12:00 AM/24:00. But I want it to be visible till 03:00 AM. So basically its tomorrow and no longer today. How can I achieve this.

pickab00 left a reply on Failed To Parse Time String (04-14-2019 07:30) At Position 0 (0)

@BOBBYBOUWMANN - I actually do have a question. Should I open a new post?

pickab00 left a reply on Failed To Parse Time String (04-14-2019 07:30) At Position 0 (0)

@BOBBYBOUWMANN - This was a really good explanation. Thank you sir. I will accept this as best answer as soon as I get back on my PC. On mobile it gives me 404 for some reason.

pickab00 started a new conversation Failed To Parse Time String (04-14-2019 07:30) At Position 0 (0)

My carbon is returning this error

DateTime::__construct(): Failed to parse time string (04-14-2019 07:30) at position 0 (0): Unexpected character

But I do not see any unexpected characters

here is the code

$parsed_date = $date; //this return   04-14-2019
    $parsed_time = $time->time; //this returns   07:30

$parse_reservation_date = Carbon::parse($parsed_date. ' ' .$parsed_time)->format('Y-m-d H:i:s:u');

return $parse_reservation_date ;
13 Apr
2 months ago

pickab00 started a new conversation Laravel Ajax If First And Second Select Equal To

So I have two select tags with options. Now so far I have a return value from my select tag if it is equal to a specific value. To put it in to perspective here is my ajax

function checkFreeMeal() {


    var url_origin   = window.location.origin;

    $('#existing_guest_selector').on('change', function() {

        var guestID = this.value;

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: "GET",
            url: url_origin + '/restaurant-reservations/check-free-meal/' + guestID,

            statusCode: {
                500: function() {
                    $('.something-went-wrong').text('err');
                }
            },
            success: function(data) {
                if (data == 1){
                    $('.free-meal').prop('checked', true);
                }if(data == 0){
                    $('.free-meal').prop('checked', false);
                }
            }
        });

    });

}

My guest ID is coming from my select option value and it is sending to URL which expects a parameter which is the guest ID.

Now I have another Select field which I would Like to use to check if the result is 1 or 0. I want to first check if the guest id returns 1. And later check if the meal plan id returns 1. If they both return 1 from a controller, do something. Currently as mentioned on the code above, My route/URL expects one param and one select change. How can I check two select change and pass those two ID's (guest ID and meal plan ID) to the route? I can write the controller from there. I just want to know How I can pass two select values in to one ajax/route. So guest on change and meal plan on change, pass two id's to the url (something like restaurant-reservations/check-free-meal/' + guestID + '/' + mealPlanID).

05 Apr
2 months ago

pickab00 left a reply on Scheduling SMS Job

@SNAPEY - A million thanks to you snapey. I now have a solid understanding of how queues, scheduler and jobs works. I created an Artisan command and just input my conditions in it. Here.

$pendingMinatenance = Maintenance::with('maintenancedepartment')->with('area')->where('created_at', '<', now()->subMinutes(120))->where('sms_sent', null)->get();

    if ($pendingMinatenance->count() > 0){

        foreach($pendingMinatenance as $pendings){

            
    //sms sending code which is really long so I deleted it.

            $pendings->sms_sent = 1;
            $pendings->update();

        }

    }

And finally I used task scheduler (because I am on windows) and called artisan command every 10 minutes. Can you please judge the code above though. That would help me improve a lot

Once again, thank you!

pickab00 left a reply on Scheduling SMS Job

@SNAPEY - Sorry for all the replies.

If I were to use Scheduler and do,

$stuckJobs = Process::where('completed', false)->where('created_at', '<', now()->subMinutes(120))->get();

Than that means that It will keep sending sms to the users which is 2 hours old. So the next 10 minutes will send another sms to the same user about the same data again. It will be repetitive. But to encounter that, I can put a field which says, sent_sms and set it to 1 or something. But I really do not want to create another col in my table. Unless my proposed method of Job delay and comaprison does not work. So what do you think Snapey? My idea of Jobs or Scheduler with a sms_sent or something like that?

pickab00 left a reply on Scheduling SMS Job

@SNAPEY - In my opinion, If I understand the concept right, then Job is better isn't it?

I mean I can simply delay the job to 2 hours and send it to my job class. Now my job class will check if the delayed job is still status pending. If so, then send SMS. But that made me think. If I delay a job to 2 hours, and I insert a new record, wouldn't that be delayed to 2 hours too? Would it create a conflict or something? How does that work

pickab00 left a reply on Scheduling SMS Job

@SNAPEY - I also have another question. Assuming that I dispatched 5 jobs in the past 5 minutes, and delayed them each for 2 hours with a condition which says if they have not being processed, where are the jobs stored till then? I am still getting used to this concept. How do they work exactly?

And if I dispatch the job, can I write the condition inside the job like this?

$time = Carbon::now()->subHour(3);

if($myInsert->created_at <=  $time && $myInsert->status == 0  ){
    //then send sms
}

So this will be my job correct? So I delay it from my controller method which will look something like this.

SendSMS::dispatch($myInsert)
            ->delay(now()->addMinutes(120));

So is this how it will be done? If I am delaying the job, I don't need to check if the time comparison do I? If I understand this correct, now my store() method will delay and send a job in 2 hours after creation and after it goes to the SendSMS job, it will check if the job is still pending. If it is pending, send sms. So I don't really need the time (3 hours) comparison in my Job SendSMS class do I?

And most importantly, where are the jobs stored if I am delaying them for 2 hours. How does that work

pickab00 left a reply on How To Check If It Has Been Two Hours Since The Created Time Using Carbon

@SNAPEY - Yes I know sorry this is to test if my conditions and everything are working fine before I finalize the code

pickab00 left a reply on Scheduling SMS Job

@SNAPEY - Snapey what about task scheduling? Can I create a task and schedule it to check every 1 hour or so and if the condition inside it matches, do something like send an email or sms. I am trying to send an SMS to departments where the jobs are incomplete and has been more than 2 hours. So what would be easier and better? I have never done this so pardon me if I sound like a newbie with scheduling and jobs. Basically I want to check for any records which is older than 2 hours every 1 hour (or minutes) and send sms to the department mobile and notify them of the job not completed. And I am on windows environment not linux. So which would be better? Jobs or Task Scheduling?

pickab00 left a reply on How To Check If It Has Been Two Hours Since The Created Time Using Carbon

@SNAPEY - In a controller to compare the current date with the date created. I want to schedule a job so I want to check if the time is greater than or equal to 3 hours

@tray2 What method would do good? diffForHumans or this:

$test = Reservation::where('created_at','<=',$time)->first();

    return $test;
//I want a collection but for testing purposes first()

Is this better or doing a comparison with diffForHumans?

pickab00 started a new conversation How To Check If It Has Been Two Hours Since The Created Time Using Carbon

How can I check if it has been 2 hours from created_at using carbon. I am unable to find in docs

pickab00 started a new conversation Scheduling SMS Job

Hello. I have the code and everything set up to send sms upon adding the data. So what I had in mind was to send an sms after the 'created_at' has been 1 hour. So after 1 hour of adding, send, do something. How is this possible? I am just simply adding a data and I want to something after 1 hour from data add time. Thanks!

03 Apr
2 months ago

pickab00 started a new conversation Pivot Table Not Getting Relationship

I have two tables. One is users and the other is menus. They have a table menu_user which is the pivot table and here is the relationship.

class Menu extends Model
{

        use SoftDeletes;

        public function users(){
        return $this->belongsToMany('App\User');
    }

}

class User extends Model
{

        use SoftDeletes;

        public function menus(){
        return $this->belongsToMany('App\Menu');
    }

}

And this is what I am trying in my controller:

$test = Auth::user()->with(['menus' => function($q){
        $q->with('menuroutes');
    }])->get();
//menuroutes is related to the menu table. menu routes belongs to menu and menu has many menuroutes.

    foreach ($test->menus as $menus){
        return $menus;
    }

    return $test;

Basically I want to take the menus belonging to the auth user but it is giving me this error.

"Property [menus] does not exist on this collection instance."

Thanks

02 Apr
2 months ago

pickab00 left a reply on Write Middleware To Deny Access To Routes

@LOSTDREAMER_NL - This gives me 403 with every URL now

pickab00 left a reply on Write Middleware To Deny Access To Routes

@LOSTDREAMER_NL - Basically anything which falls behind the defined link inside the table gives me 403. So how can I tell that if the /restaurant-reservations/reservation is accessible, then, /restaurant-reservations/reservation. But if the /user-management is not accessible, then don't allow /user-management/1/edit

sorry if this is complicating

pickab00 left a reply on Write Middleware To Deny Access To Routes

@LOSTDREAMER_NL - This worked but the problem now is this.

The links are given like so...

/reservations/create /reservations/1/edit /user-management

So the route is something.io/reservations/create. This works as intended if the user does not have the menu item. But when I go to /user-management (which is outside of the reservations route group), and go to /user-management/1/edit it gives me 403

pickab00 started a new conversation Write Middleware To Deny Access To Routes

So in my laravel app I can menu items to each user. It works like tags. A pivot table handles belongsToMany relationship on both the tables (users table and menus table). Now the menu table has routes, name, icon etc. This acts as the menu items displayed on the left of the app. What I want to achieve is to be able to deny access to a route if the user does not have that menu item. So far what I have is this code in a middleware.

$auth_menu = User::with(['menus' => function($q){
            $q->whereIn('type', [1, 3])->orderBy('menu_index', 'asc');
        }])->findOrFail($auth->id);

So what that does is, it takes the authenticated user, and finds the user and get the related menu items to that user. Now how can I tell laravel to deny access to that route or abort to 404 if the user does not have a menu item. I want to do this because even though menu items are not displayed, they can still access from url

pickab00 left a reply on Getting 500 Error JQuery

@SNAPEY - It works as intended. It either returns 0 or 1 depending on the logic. I can not reproduce the error when I directly access the url with an ID

pickab00 started a new conversation Question About Base Controller

I wanted to share a variable with all my views so I went on ahead and used my Service provider boot() method to share my variable with all my views using View::share. But the problem was, I had to take the auth user information and as the service provider is loaded before, it returns null.

So I went on ahead and tried this.

public function __construct()
{
    $this->middleware(function ($request, $next) {

        $auth = Auth::user();

        $auth_menu = User::with('menus')->findOrFail($auth->id);

        view()->share('auth_menu', $auth_menu);

        return $next($request);
    });

}

This is inside of my Controller. As in the main controller which extends to base controller and I wanted to know if this method is

A. Safe? B. Good practice?

I did try to get it in to a middleware

Now the second thing I did was to make a middleware ShareMenuVariable:

public function handle($request, Closure $next) {

    $auth = Auth::user();

    $auth_menu = User::with('menus')->findOrFail($auth->id);

    view()->share('auth_menu', $auth_menu);

    return $next($request);
}

And in my kernel I called it in my web group \App\Http\Middleware\ShareMenuVariable::class, so it will always run in web routes.

So which method is better/safe/best practice and which method should I be using and why?

pickab00 left a reply on Getting 500 Error JQuery

@SNAPEY - Yes there is no mention of any errors of 500 or routing errors or GET errors for that specific controller or block

01 Apr
2 months ago

pickab00 left a reply on Getting 500 Error JQuery

@SNAPEY - Ok so here is what I tried to do now.

I tried to give var guestID = 1 manually (because that exists in table and is valid). But I am still getting the error. Except, the error is GET http://test.io/reservations/get-preference/1 500 (Internal Server Error). And network shows:

{
    "message": "Server Error"
}{
    "message": "Server Error"
}

Thats all the info there. And like I mentioned before, it only happens on dev mode with clear cache