Need some coding help - Laravel

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,147
Reaction score
10,489
I have a site, and it's built in or using Laravel (I'm no coding guy, so you'll excuse my lack of ability to articulate things properly).

But my problem is simple. I have this line of code:

Code:
<li><a href="{{ url('/support') }}">@lang('menus.support')</a></li>

It's a support tab on my site. When users or admin receive a reply, I want to make it so that a little icon or number appears next to the tab. On another part of the site there is a function that informs users of new messages, basically, using this:

Code:
<h3>{{ $unreadMessages }}</h3>

Now, I tried a number of variations:

Code:
<li>{{ $unreadMessages }}<a href="{{ url('/support') }}">@lang('menus.support')</a></li>

<li><a href="{{ url('/support') }}">@lang('menus.support') {{ $unreadMessages }}</a></li>

<li><a href="{{ url('/support') }}">@lang('menus.support')</a>{{ $unreadMessages }}</li>

I tried these and a few others, and it Works. The notification appears. HOWEVER, after I make the change, when I try to visit any page other than the Dashboard page on the site, or if I log out and login again, I get greeted with a big blank page that says:

Whoops, looks like something went wrong.

If I remove the change I made, the site works normally again.

How is this possible? I'm a CSS/HTML guy. You know, a bit of a dinosaur. But this is a simple little baby change, and in CSS or HTML this would work 100% in 3 seconds and no issues. The only issue I would have is to implement the notification in the right size and margins and stuff.

So, any ideas guys?
 
I think you are better off sharing this at stackoverflow.

From the bits you've shared, it looks like the variable $unreadMessages is not properly assigned from your controller file. Hence, it works when there are unread messages, but throws an error when there aren't any.

Try to add this block before you are calling $unreadMessages, and see if it works.
Code:
@php

if( !isset( $unreadMessages) ) $unreadMessages = null;

@endphp

I am a bit confused though, as in $unreadMessages is more likely to be an array then a string.

Happy holidays.
 
I think you are better off sharing this at stackoverflow.

From the bits you've shared, it looks like the variable $unreadMessages is not properly assigned from your controller file. Hence, it works when there are unread messages, but throws an error when there aren't any.

Try to add this block before you are calling $unreadMessages, and see if it works.
Code:
@php

if( !isset( $unreadMessages) ) $unreadMessages = null;

@endphp

I am a bit confused though, as in $unreadMessages is more likely to be an array then a string.

Happy holidays.

Hey man, thanks for replying. Happy holidays :)

Frankly, I'm not sure if it's an array or a string. Couldn't tell you the difference between the two to save my life...

The $unreadmessage variable works fine on the dashboard page. When the user has a new message, it shows 1 (or the number of unread messages). When the user reads the message, that becomes 0. It works like that.

But when I try to implement it on the header of the site next to the Tickets button, I get the problem I told you about. It actually displays the number of unread messages, but if I try to open any page other than the Dashboard page I get a blank page with the error.

It's like there's something somewhere that prevents it from getting accepted. But Laravel is a complicated son of a bitch, and brand new to me, so I have no idea how to proceed.
 
Please dont take this otherwise, its not possible to suggest a proper fix without knowing the codebase. I am trying to suggest solutions only based assumptions I made from what you've mentioned.

The $unreadmessage variable works fine on the dashboard page.

... but if I try to open any page other than the Dashboard page I get a blank page with the error.

Its most likely, this variable is not set in other pages. Thats why php is complaining that it cant find it.

To set the $unreadMessages in other pages, you will need to find other controllers that are rendering your pages and set $unreadMessages as template variable.

You can look into your dashboard controller for how its set. (that file should be in app/controllers/dashboard)

Something along the line..
Code:
public function index(){
   return view('dashboard', ['unreadMessages' => $unreadCount]);
}

A quick fix would be this -

Replace this
Code:
<li>{{ $unreadMessages }}<a href="{{ url('/support') }}">@lang('menus.support')</a></li>
With this
Code:
@php
if( !isset( $unreadMessages) ) $unreadMessages = 0; 
@endphp
<li>{{ $unreadMessages }}<a href="{{ url('/support') }}">@lang('menus.support')</a></li>

This should suppress the errors. But note, for all pages other than dashboard - your unread count would still be showing 0. (as I mentioned earlier - its not set by the controller)

Hope this helps :)
 
Please dont take this otherwise, its not possible to suggest a proper fix without knowing the codebase. I am trying to suggest solutions only based assumptions I made from what you've mentioned.

Its most likely, this variable is not set in other pages. Thats why php is complaining that it cant find it.

To set the $unreadMessages in other pages, you will need to find other controllers that are rendering your pages and set $unreadMessages as template variable.

You can look into your dashboard controller for how its set. (that file should be in app/controllers/dashboard)

Something along the line..
Code:
public function index(){
   return view('dashboard', ['unreadMessages' => $unreadCount]);
}

All good until I openeed app... there's no controllers folder in it, and I don't see a "dashboard" file anywhere either.


A quick fix would be this -

Replace this

With this
Code:
@php
if( !isset( $unreadMessages) ) $unreadMessages = 0;
@endphp
<li>{{ $unreadMessages }}<a href="{{ url('/support') }}">@lang('menus.support')</a></li>

This should suppress the errors. But note, for all pages other than dashboard - your unread count would still be showing 0. (as I mentioned earlier - its not set by the controller)

Hope this helps :)

Well I'll be damned. That worked! :)

And you're absolutely right. When I'm on the dashboard page it shows 1 as message correctly. But if I navigate to any of the other pages it shows 0. Even on the support page (where the ticket can be opened) it shows 0, only on the dashboard page does it show 1 correctly.

You're 100% right on that. Everything you said is correct. But that's no solution, as you mentioned. I'd need to figure out how to do the first bit of your message in order to apply this properly.

Do you see anything here that could help find the dashboard file (that's the app folder)?

GX9Gq0c
 
Actually... you're probably not talking about this. But I do have dashboard.blade.php, and this is where I got the {{ $unreadMessages }} code from:

Code:
                <div class="col-md-4">
                    <div class="tile">
                        <h3 class="tile-title">@lang('general.new_messages')</h3>
                        <h3>{{ $unreadMessages }}</h3>
                    </div>
                </div>

Does that help?
 
Glad that its working.

Sorry, my bad, you can find your controllers under the http folder. So the path would be like -

Code:
your_project_home/app/http/controllers

I am not sure, how your controllers are structured. But folder names should be self explanatory.

In any case you can trace your controllers from the routes file. You should find your routes file here

Code:
your_project_home/routes/web.php

Just a little info on how it works -

When you type an address, say yourdomain.com/dashboard

Laravel looks into the routes file for /dashboard and loads the appropriate controller file. Controller then finally loads the view.

The file you mentioned is a blade template file. Its used to create the view html.

Hope this helps. Happy Coding :)
 
Glad that its working.

Sorry, my bad, you can find your controllers under the http folder. So the path would be like -

Code:
your_project_home/app/http/controllers

I am not sure, how your controllers are structured. But folder names should be self explanatory.

In any case you can trace your controllers from the routes file. You should find your routes file here

Code:
your_project_home/routes/web.php

Just a little info on how it works -

When you type an address, say yourdomain.com/dashboard

Laravel looks into the routes file for /dashboard and loads the appropriate controller file. Controller then finally loads the view.

The file you mentioned is a blade template file. Its used to create the view html.

Hope this helps. Happy Coding :)

Thanks for the lesson :)

I found and opened the dashboardcontroller.php, but it's just 125 lines of random characters. A bunch of nothing really. And no "unreadmessages" line anywhere.

Q3tPCXu


I made that blue mess there because I'm not sure if there's any risk of sharing that in the open (noob lol).

I also opened /routes/web.php and searched for the line "unreadmessages" and there's nothing there.

When I opened dashboardcontroller.php I was expecting to find something normal, because you said:

Its most likely, this variable is not set in other pages. Thats why php is complaining that it cant find it.

To set the $unreadMessages in other pages, you will need to find other controllers that are rendering your pages and set $unreadMessages as template variable.

You can look into your dashboard controller for how its set. (that file should be in app/controllers/dashboard)

Something along the line..
Code:
public function index(){
   return view('dashboard', ['unreadMessages' => $unreadCount]);
}

But it's just a bunch of nothing o_O
 
Oh man. This looks like a dead end.

This garbled text means its encrypted - using ioncube. There are a few decompilers online, havent used them personally - so cant say much about them.

You should contact your developer for the source.
 
Oh man. This looks like a dead end.

This garbled text means its encrypted - using ioncube. There are a few decompilers online, havent used them personally - so cant say much about them.

You should contact your developer for the source.

Okay, so the developer got it locked tight, I can't fuck with it much.

That's okay...

I guess, start making Big money, hire someone to decode all that shit, remove license, get me free of this oppression!!! :D

Thanks for trying bro. Even though we got nowhere, I did learn a thing about a thing or two Laravel.

Cheers :)
 
Back
Top