Laravel Route request - laravel

I have make the notifications. but Notifications send perfectly.When I click notification not gone to the Notification for more details.
Route issue
<a href="{{URL::to("surveys/59")}}">
<li class="list-group-item notifictionhover">
<strong>{{$notification["data"]["fromuser"]["name"]}}</strong>
Commented On Survey <strong>{{$notification["data"]["survey"]["title"]}}</strong>
<strong>{{$notification["data"]["comment"]["text"]}}</strong>
<div>{{$notification["created_at"]}}</div>
</li>
</a>
My Web.php Route define
Route::resource("surveys","SurveyController");

Related

Notification link breaks when registering a new user laravel

I'm using Laravel's notification table and a foreach loop to get the notifications from the user. so I can change the CSS if there are unread notifications in the navbar. It works fine after the user gets the notification but when registering a new user that has never been notified. It shows HTML with the URL:
" href="http://127.0.0.1:8000/notifications/index">NotificationsMy profileProfile settingspost
I want to show the notification link regardless if there are no notifications or not, but I want to change the styling depending on if there are unread notifications or not.
#foreach(auth()->user()->notifications as $notification)
<a class="#if($notification->read_at<$notification->created_at) px-4 py-2
mt-2 ... more css
#else px-4 py-2 mt-2... more css #endif #endforeach" href="{{ route('notifications.index') }}">Notifications</a>
#endforeach

Method Illuminate\Auth\SessionGuard::users does not exist in Laravel

I am trying to attach the roles, users, and users_role tables. Trying to connect them and checking on the Blade file that if a user's role is admin, he can only access the user's route; otherwise, he can't access it. For other users, the users' route must not be seen. At the same time, verifying code on the Blade file throws an error. How can I solve this in the latest Laravel 8?
app.blade.php
#if(Auth::users()->roles()->where('name', 'Admin')->exists())
<li class="nav-item">
<a class="nav-link" href="{{ url('/Admin/users')}}">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url('/Admin/Posts')}}">Posts</a>
</li>
#else
<li class="nav-item">
<a class="nav-link" href="{{ url('/Admin/Posts')}}">Posts</a>
</li>
#endif
Role model
public function users()
{
return $this->belongsToMany(User::class, 'users_roles', 'user_id', 'role_id')
->using(UserRole::class);
}
User model
public function roles()
{
return $this->belongsToMany(role::class, 'users_roles', 'role_id',
'user_id')->using(UserRole::class)->withPivot('name');
}
Error
Simply Replace this
#if(Auth::users()->roles()->where('name', 'Admin')->exists())
Into
#if(\Auth::user()->roles =='Admin')
I hope you got your solution .
with the help of rakesh answer https://stackoverflow.com/a/68176136/16114539
and some modification , the error got solved ..
so you can check the current user and check role of it and then show it the code is like:
#if(Auth::check() && Auth::user()->roles()->where('name', 'Admin')->exists())
it get solved

I am new in laravel and I want to announcement on homepage

Actually I want to display admin announcement or any notification on home page so when ever any user will be login with credentials detail so he or she can see announcement or notification..
please help me step by step , if possible with code logic, please do for me thank you very much
as you requested for full step by step process try this
first make form in your admin panel like this
<form method="post" action="{{ route('announcement') }}">
<label>Enter Your Announcement</label>
<textarea class="form-control" name="text">
</textarea>
<select name="active_status">
<option value="0">Deactive</option>
<option value="1">Active</option>
</select>
</form>
open your route/web.php make post method
Route::post('/announcement', [
'uses' => 'AdminController#postAnnouncement',
'as' => announcement
]);
if you have AdminController and its okay if not make it with these commands
php artisan make:controller AdminController
now you can add your function for save your announcement to database
public function postAnnouncement(Request $request){
$announcement = new Announcement;
$announcement->text = $request->text;
$announcement->active = $request->active_status;
$announcement->save();
return back()->with('status', 'Announcement Posted Success');
}
add use App\Announcement; in top of your controller
now you need to make announcement table and model
php artisan make:model Announcement -m
it will generate 2 file model & migration
go to database/migration folder and add this line to announcement migration after
$table->increments('id');
$table->string('text');
$table->boolean('active');
your table is ready to migrate now
php artisan migrate
now you can show in your homepage like this
first goto your homecontroller & add these lines
$announcements = App\Announcement::where('active', true)->get();
return view('home', compact('announcements'));
in your home.blade.php file
//Only for Authenticated Users
#auth
#foreach($announcements as $announcement)
<p>{{ $announcement->text }}</p>
#endforeach
#endauth
//Only for Guest Users
#guest
#foreach($announcements as $announcement)
<p>{{ $announcement->text }}</p>
#endforeach
#endguest
You can do it simply with the help of built-in user model.
First, check if the user is authorized and after that, you can show the announcement section.
All this should be done in the view of your page. you can do something like this
#if (Auth::check())
//show authorized content (Announcements etc.)
#else
//show unauthorized content
#endif
Or you can also do this in laravel 5.6
#auth
// The user is authenticated...
#endauth
#guest
// The user is not authenticated...
#endguest
Also do some research for this there are plenty of examples there on the Internet.
Try This
#auth
// For Logged in users only
<h1> You Are Loged In</h1>
#endauth
#guest
// For Guest Users
<h1> You Are Guest </h1>
#endguest
#auth
//if user logged in
<h1> You Are Loged In</h1>
#else
else guest
<h1> You Are Guest </h1>
#endauth

Why if I add the id attribute to span inside bootstrap navbar the JSP/Tiles exceptions aren't shown?

I found a weird problem in my project. I'm using Spring MVC, Tiles, JSPX and Boostrap.
I have a navbar in my header page, then I added a span to show a badge like https://getbootstrap.com/docs/3.3/components/#badges.
Till here nothing strange. But If I add an id on span tag and there is an error inside the html code, I can't see any log or exception.
Here the code
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-male"><jsp:text/></span>
<span class="badge badgeNavbar" id="badgesContrattiDaApprovare">
<jsp:text/>
</span> ${clienti}
<span class="caret"><jsp:text/></span>
</a>
<ul class="dropdown-menu">
...
</ul>
Instead If I remove id="badgesContrattiDaApprovare" I can see the exceptions.
Are there any conflicts between span and id?
SO: Why if I add the id attribute to the span inside bootstrap navbar the JSP/Tiles exceptions aren't shown inside the rendered view?
For example here if an exception occurs without the id attribute:
Instead, if I add the id attribute is like the rendering is stopped, and I see only a blank page. The generated/rendered html code is incomplete.

Laravel: request::is() and request::patch()

Can somebody explain me difeerence between
Request::is()
and
Request::patch()
??
I used request::is in my code to active navbar like this, but i saw that somebody use too request::patch
<div class="nav-collapse">
<ul class="nav">
<li class="{{ Request::is('/') ? 'active' : ''}}"><a href="/">#
</a</li>
#foreach($categories as $category)
<li class="{{ Request::is($category->name) ? 'active' : '' }}">
{{$category->name}}</li>
#endforeach
</ul>
</div>
In Side patch Request :
patch request says . only send the data which one you want to update
and it won't effecting or changing other data . so no need to send all
value again . just i want to update my first name so i need to send
only first name to update .
In Side Is Request :
https://indigotree.co.uk/laravel-4-using-request-is-named-routes/
Laravel 4.1 Request::is for active menu not working
Example
<li
{{{ (Request::is('/core') ? 'class=active' : '') }}}>Control Panel
</li>
and Check 'class="active"' to 'class=active'
This working fine for <li> tag but not <a> tag, needs to be used like so:
Overview

Resources