Right Nav Bar error, Not authenticate in Laravel - php

In my web-app i made a profile section . But the problem is when it goes to dashboard in right-navbar it has my profile and logout. when i click on my profile-> in my profile page the right-navbar became register and sign in instead of name and logout. I think some authentication issue is there. please suggest how to fix it. check screenshots also for better understanding.
app.blade.php
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- Left Side Of Navbar -->
<ul class="navbar-nav mr-auto">
</ul>
<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
#auth
<a class="dropdown-item" href="{{ route('profiles.show', Auth::user()->profile->id) }}">
My Profile
</a>
#endauth
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
#endguest
</ul>
</div>
</div>
profiles/show.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
{{ $profile->name }}
</div>
<div class="card-body">
<form id="update-profile-form" action="{{ route('profiles.update' , $profile->id) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PATCH')
<div class="form-group row justify-content-center">
<div class='profile-avatar'>
<div onclick="document.getElementById('image').click()" class="profile-avatar-overlay">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 32 32">
<path d="M18 22.082v-1.649c2.203-1.241 4-4.337 4-7.432 0-4.971 0-9-6-9s-6 4.029-6 9c0 3.096 1.797 6.191 4 7.432v1.649c-6.784 0.555-12 3.888-12 7.918h28c0-4.030-5.216-7.364-12-7.918z"></path>
</svg>
</div>
<img src="{{ URL::to('image/' .$profile->image()) }}" alt="" >
</div>
</div>
<input onchange="document.getElementById('update-profile-form').submit()" style="display: none;" id="image" type="file" name="image">
<div class="form-group">
<label for="name" class="form-control-label">
Name
</label>
<input id="name" name="name" value="{{ $profile->name }}" type="text" class="form-control">
</div>
<div class="form-group">
<label for="description" class="form-control-label">
Description
</label>
<textarea name="description" id="description" rows="3" class="form-control">{{ $profile->description }}</textarea>
</div>
<button type="submit" class="btn btn-info">
update profile
</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
ProfileController.php
class ProfileController extends Controller
{
public function show(Profile $profile)
{
return view('profiles.show', compact('profile'));
}
public function update(Request $request, Profile $profile)
{
if ($request->hasFile('image'))
{
$profile->clearMediaCollection('images');
$profile->addMediaFromRequest('image')
->toMediaCollection('images');
}
return redirect()->back();
}
}

Related

undefined variable reimage laravel

I am trying to crud the image but it say undefined variable reimage
code:
CategoryController
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.category.add');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'title' => 'required|min:5|max:20',
'detail' => 'required',
'cat_image' => 'required',
]);
if($request->hasFile('cat_image')){
$image = $request->file('cat_image');
$reimage = time().'.'.$image->getClientOriginalExtension();
$dest = public_path('/imgs');
$image->move($dest,$reimage);
}
$category = new Category;
$category->title= $request->title;
$category->title= $request->title;
$category->image= $reimage;
$category->save();
return redirect('admin/category/create')->with('Data has been added succesfully');
}
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\CategoryController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
/* Route::get('/', function () {
return view('welcome');
}); */
Route::get('/',[HomeController::class,'home']);
Route::get('/login',[AdminController::class,'login']);
Route::post('/login',[AdminController::class,'submit_login'])->name('submit_login');
Route::get('/admin',[AdminController::class,'dashboard']);
Route::resource('/admin/category',CategoryController::class)
add.blade.php
**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Static Navigation - SB Admin</title>
<link href="{{ URL::to('/css/styles.css') }}" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js" crossorigin="anonymous"></script>
</head>
<body>
<nav class="sb-topnav navbar navbar-expand navbar-dark bg-dark">
<!-- Navbar Brand-->
<a class="navbar-brand ps-3" href="index.html">Start Bootstrap</a>
<!-- Sidebar Toggle-->
<button class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#!"><i class="fas fa-bars"></i></button>
<!-- Navbar Search-->
<form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
<div class="input-group">
<input class="form-control" type="text" placeholder="Search for..." aria-label="Search for..." aria-describedby="btnNavbarSearch" />
<button class="btn btn-primary" id="btnNavbarSearch" type="button"><i class="fas fa-search"></i></button>
</div>
</form>
<!-- Navbar-->
<ul class="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-user fa-fw"></i></a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#!">Settings</a></li>
<li><a class="dropdown-item" href="#!">Activity Log</a></li>
<li><hr class="dropdown-divider" /></li>
<li><a class="dropdown-item" href="#!">Logout</a></li>
</ul>
</li>
</ul>
</nav>
<div id="layoutSidenav">
<div id="layoutSidenav_nav">
<nav class="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
<div class="sb-sidenav-menu">
<div class="nav">
<div class="sb-sidenav-menu-heading">Core</div>
<a class="nav-link" href="index.html">
<div class="sb-nav-link-icon"><i class="fas fa-tachometer-alt"></i></div>
Dashboard
</a>
<div class="sb-sidenav-menu-heading">Interface</div>
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapseLayouts" aria-expanded="false" aria-controls="collapseLayouts">
<div class="sb-nav-link-icon"><i class="fas fa-columns"></i></div>
Layouts
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="collapseLayouts" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordion">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="layout-static.html">Static Navigation</a>
<a class="nav-link" href="layout-sidenav-light.html">Light Sidenav</a>
</nav>
</div>
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapsePages" aria-expanded="false" aria-controls="collapsePages">
<div class="sb-nav-link-icon"><i class="fas fa-book-open"></i></div>
Pages
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="collapsePages" aria-labelledby="headingTwo" data-bs-parent="#sidenavAccordion">
<nav class="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
Authentication
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="pagesCollapseAuth" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordionPages">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="login.html">Login</a>
<a class="nav-link" href="register.html">Register</a>
<a class="nav-link" href="password.html">Forgot Password</a>
</nav>
</div>
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseError" aria-expanded="false" aria-controls="pagesCollapseError">
Error
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="pagesCollapseError" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordionPages">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="401.html">401 Page</a>
<a class="nav-link" href="404.html">404 Page</a>
<a class="nav-link" href="500.html">500 Page</a>
</nav>
</div>
</nav>
</div>
<div class="sb-sidenav-menu-heading">Addons</div>
<a class="nav-link" href="charts.html">
<div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div>
Charts
</a>
<a class="nav-link" href="tables.html">
<div class="sb-nav-link-icon"><i class="fas fa-table"></i></div>
Tables
</a>
</div>
</div>
<div class="sb-sidenav-footer">
<div class="small">Logged in as:</div>
Start Bootstrap
</div>
</nav>
</div>
<div id="layoutSidenav_content">
<main>
<div class="container-fluid px-4">
<h1 class="mt-4">Create Category</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item">Dashboard</li>
<li class="breadcrumb-item active">Create Category</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<h1>Create</h1>
</div>
<div class="card-body">
#if($errors)
#foreach($errors->all() as $error)
<p class="text-danger">{{ $error }}</p>
#endforeach
#endif
#if(Session::has('success'))
<p class="text-danger">{{ session('success') }}</p>
#endif
<form method="POST" action="{{ url('admin/category') }}" encrypt="multipart/form-data">
#csrf
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" class="form-control" name="title" placeholder="Enter Title">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Detail</label>
<input type="text" class="form-control" name="detail" placeholder="Enter details about the category">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Image</label>
<input type="file" class="form-control" name="cat_image" placeholder="Image">
<small id="emailHelp" class="form-text text-muted">a jpg or png</small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
<div style="height: 100vh"></div>
<div class="card mb-4"><div class="card-body">When scrolling, the navigation stays at the top of the page. This is the end of the static navigation demo.</div></div>
</div>
</main>
<footer class="py-4 bg-light mt-auto">
<div class="container-fluid px-4">
<div class="d-flex align-items-center justify-content-between small">
<div class="text-muted">Copyright © Your Website 2021</div>
<div>
Privacy Policy
·
Terms & Conditions
</div>
</div>
</div>
</footer>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="{{ URL::to('/js/scripts.js') }}"></script>
</body>
</html>
and I am trying to make new name for the photo as the name is time+the orginal name
ml>
and I am trying to make new name for the photo as the name is time+the orginal name
ml>
and I am trying to make new name for the photo as the name is time+the orginal name
ml>
and I am trying to make new name for the photo as the name is time+the orginal name
ml>
and I am trying to make new name for the photo as the name is time+the orginal name
**
You are getting variable undefined because its only initialized inside IF condition and used below that code. In case IF condition is not true, variable never created and giving your error.
Simply initialized variable with empty string (or something else if its required DB field).
Here is your updated function
public function store(Request $request)
{
$request->validate([
'title' => 'required|min:5|max:20',
'detail' => 'required',
'cat_image' => 'required',
]);
$reimage = '';
if($request->hasFile('cat_image')){
$image = $request->file('cat_image');
$reimage = time().'.'.$image->getClientOriginalExtension();
$dest = public_path('/imgs');
$image->move($dest,$reimage);
}
$category = new Category;
$category->title= $request->title;
$category->title= $request->title;
$category->image= $reimage;
$category->save();
return redirect('admin/category/create')->with('Data has been added succesfully');
}
Also there is an error in html, form enctype is mis-spelled, and fix it and you will be receiving files on backend:
Yours
<form method="POST" action="{{ url('admin/category') }}" encrypt="multipart/form-data">
Correct one:
<form method="POST" action="{{ url('admin/category') }}" enctype="multipart/form-data">

Laravel: Missing required parameters (I want to create a product list)

I am building a Laravel application with shopping cart function. I am following instructions in this website(Create a Shopping Cart with Laravel 6) with small alteration to match what I want to build.
What I want to do is show a list of products of each store according to the parameter of a url.
example:
https://productlist/1 => show product list of shop1
https://productlist/2 => show product list of shop2
I am trying to do this following the website I mentioned before, and here's the error I got.
Missing required parameters for [Route: shop] [URI: menu/{user}]. (View: C:\Users\toyop\Desktop\myproject\resources\views\partials\navbar.blade.php)
http://localhost:8000/menu/1
Since navbar.blade.php is mentioned in the error I thought there's where tha problem is but I couldn't find any parameters in there.
Here are my codes.
web.php
<?php
namespace App\Http\Controllers;
use App\Product;
use App\Models\User;
use Illuminate\Http\Request;
class CartController extends Controller
{
public function shop($user)
{
$user = User::findOrFail($user);
return view('shop')->withTitle('E-COMMERCE STORE | SHOP')->with(['user' => $user]);
}
public function cart()
{
$cartCollection = \Cart::getContent();
//dd($cartCollection);
return view('cart')->withTitle('E-COMMERCE STORE | CART')->with(['cartCollection' => $cartCollection]);;
}
public function add(Request $request)
{
\Cart::add(array(
'id' => $request->id,
'name' => $request->name,
'price' => $request->price,
'quantity' => $request->quantity,
'attributes' => array(
'image' => $request->img,
'slug' => $request->slug
)
));
return redirect()->route('cart.index')->with('success_msg', 'Item is Added to Cart!');
}
public function remove(Request $request)
{
\Cart::remove($request->id);
return redirect()->route('cart.index')->with('success_msg', 'Item is removed!');
}
public function update(Request $request)
{
\Cart::update(
$request->id,
array(
'quantity' => array(
'relative' => false,
'value' => $request->quantity
),
)
);
return redirect()->route('cart.index')->with('success_msg', 'Cart is Updated!');
}
public function clear()
{
\Cart::clear();
return redirect()->route('cart')->with('success_msg', 'Car is cleared!');
}
}
show.blade.php
#extends('layouts.app3')
#section('content')
<div class="container" style="margin-top: 80px">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active" aria-current="page">Shop</li>
</ol>
</nav>
<div class="row justify-content-center">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-7">
<h4>Products In Our Store</h4>
</div>
</div>
<hr>
<div class="row">
#foreach($user->products as $pro)
<div class="col-lg-3">
<div class="card" style="margin-bottom: 20px; height: auto;">
<img src="/storage/image/{{$pro->image}}" class="card-img-top mx-auto" style="height: 150px; width: 150px;display: block;" alt="{{ $pro->image }}">
<div class="card-body">
<a href="">
<h6 class="card-title">{{ $pro->name }}</h6>
</a>
<p>${{ $pro->price }}</p>
<form action="{{ route('cart.store') }}" method="POST">
{{ csrf_field() }}
<input type="hidden" value="{{ $pro->id }}" id="id" name="id">
<input type="hidden" value="{{ $pro->name }}" id="name" name="name">
<input type="hidden" value="{{ $pro->price }}" id="price" name="price">
<input type="hidden" value="{{ $pro->image }}" id="img" name="img">
<input type="hidden" value="1" id="quantity" name="quantity">
<div class="card-footer" style="background-color: white;">
<div class="row">
<button class="btn btn-secondary btn-sm" class="tooltip-test" title="add to cart">
<i class="fa fa-shopping-cart"></i> add to cart
</button>
</div>
</div>
</form>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
#endsection
navbar.blade.php
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark shadow-sm">
<div class="container">
<a class="navbar-brand" href="{{ url('/') }}">
E-COMMERCE STORE
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="{{ route('shop') }}">SHOP</a>
</li>
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="badge badge-pill badge-dark">
<i class="fa fa-shopping-cart"></i> {{ \Cart::getTotalQuantity()}}
</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown" style="width: 450px; padding: 0px; border-color: #9DA0A2">
<ul class="list-group" style="margin: 20px;">
#include('partials.cart-drop')
</ul>
</div>
</li>
</ul>
</div>
</div>
Any help would be appreciated as I have tried multiple methods with no success.
Thank you in advance.

Laravel : after adding make:auth getting an error in my login/register page

i've made a laravel newswebsite. i've tried to add auth by doing make:auth, but when i click the button login or register it gives me an error like this:
i dont know where it is coming from. it refers to a function in my controller but i dont know why cause it doesnt need that function at all. i usually dont have errors while adding authorization. is there anyone who's had the same problem or anyone who knows how to fix it?
app.blade.php
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<link rel="stylesheet" href="{{asset('css/custom.css')}}">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<title>{{config('app.name', 'News')}}</title>
</head>
<body>
#include('inc.navbar')
#include('inc.messages')
#yield('content')
#include('inc.footer')
</body>
navbar.blade.php
<header>
<div class="container-fluid">
<div class="row headercontent">
<div class="col-md-3 offset-md-1 borderbottom">
</div>
<div class="col-md-4 borderbottom header-logo bg-white">
<a href="{{url('/')}}"><img class="high-pic"
src="https://upload.wikimedia.org/wikipedia/commons/7/77/The_New_York_Times_logo.png"
style="width: 100%;"></a>
</div>
<div class="col-md-3 search">
<span class="fas fa-search"></span>
<input type="text" class="borderbottom backgroundtextinput"
style="position:absolute; bottom:0; width:80%;outline:none;">
</div>
</div>
<div class="row logo-NY">
<div class="col-md-6 offset-md-3 borderbottom header-logo bg-white">
<div style="z-index:3000;"></div>
<a href="{{url('/')}}"><img class="high-pic"
src="https://upload.wikimedia.org/wikipedia/commons/7/77/The_New_York_Times_logo.png"
style="width: 100%;"></a>
</div>
<div class="col-md-3">
<div id="clickme" class="d-lg-none">
<i class="fas fa-arrow-down"></i>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div>
<div class="desktop-nav">
<nav class="navbar navbar-expand-lg navbar-light font">
<div class="container">
<div class="" id="navbarSupportedContent" style="margin:auto;">
<div class="navbar-flex fontcolorblack">
#foreach($categories_navbar as $item)
<div class="nav-item">
<a class="nav-link bold" href="{{url($item->naam)}}">{{ucfirst($item->naam)}}</a>
</div>
#endforeach
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
#endguest
</div>
</div>
</div>
</nav>
</div>
<div id="mobile-nav" style="width: 100%; display: none; background-color: #2e3192; color: #fff;">
<div id="closeme" class="d-lg-none">
<i class="fas fa-times fa-2x"></i>
</div>
<nav class="navbar navbar-light bg-light fixed-top d-lg-none" style="z-index:999;">
<ul class="navbar-nav mr-auto">
<a href="{{url('/')}}"><img class="high-pic"
src="https://upload.wikimedia.org/wikipedia/commons/7/77/The_New_York_Times_logo.png"
style="width: 100%;"></a>
#foreach($categories_navbar as $item)
<div class="nav-item">
<a class="nav-link bold" href="{{url($item->naam)}}">{{ucfirst($item->naam)}}</a>
</div>
#endforeach
<form class="form-inline my-2 my-lg-0" id="search_mobile" action="search" method="get">
<input class="form-control mr-sm-2" name="search" type="search" placeholder="Search..."
aria-label="Search">
</form>
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
#endguest
</ul>
</nav>
</div>
</header>
It seems to me that the problem actually is in the above line.
$category = Categorie::where('naam',$category)->first();
This line is not returning any data. Try putting dd($category) after this line to check if there is indeed a category with your query.
Probably you are trying to access non-existing category, this page should return 404 error.
after $category = Categorie::where('naam',$category)->first();
add line
abort_if(is_null($category), 404);
and it will return 404 error as it must be.
Try to debug like this,
public function oversight($category){
try{
$getCategory = Categorie::where('naam',$category)->first();
if($getCategory !== null){
dd("I GOT SELECTED CATEGORY ROW");
}else{
dd("I THINK THERE IS NO DATA AVAIALBLE BASED ON WHERE Condition");
}
dd("ALL FINE I AM GOING BACK TO VIEW WITH DATA");
}catch(\Exception $e){
dd("I GOT THIS ERROR : ".$e->getMessage());
}
}
I'm sure you'll able to fix problem by this.
As Narbil Farhan stated, the problem is in the line:
$category = Categorie::where('naam',$category)->first();
You seem to get no result from the Categorie table. First problem can be that the table does not exist, note that Laravel searches for the table 'Categories' (Searches for model name + s). You should probably catch the error if there is no data returned, like Nevermind23 suggested.
if(isset($category->id) && $category->id != ""){
$artikels = Artikel::where('category_id', $category->id)->get()
}
Personal note, try to prevent programming in your native language. This is harder for non Dutch speakings to understand your code.
There are multiple solutions:
Solution:
$category = Categorie::where('naam', $category)->first();
if(#category){
//you can get the $artikels belonging to the category
}
In this case, if there are no category with the respective name, $category will be null, and the code inside IF statement will not be executed.
Solution:
$category = Categorie::where('naam', $category)->firstOrFail();
//you can get the $artikels belonging to the category
In this case, if the Category is not found, an Illuminate\Database\Eloquent\ModelNotFoundException will be thrown. If the exception is not caught, a 404 HTTP response is automatically sent back to the user.
Solution: Route model binding - see the documentation
public function oversight(Categorie $category) {
return view('pages.oversight', ['category'=>$category]);
}
In this case, if there is no category with the respective name/id, a 404 HTTP response is automatically sent back to the user.
Also, I'd suggest you, to create a( most probably OneToMany) relationship between the Categorie and Artikel model. It will make your life much simpler :)

Why is appering a pagination error after click in the search button?

I have a page "https://proj.test/user/profile?user=2#myRegistrations" where I have two tabs, one tab show the past registrations of a user in conferences and other tab the next registrations of the user in a conference. The user can click "Past Registrations" to check the past registrations and click in "Next Registrations" to check his next registrations in conferences. And its working.
In this same page, above the tabs, I have a form for the user to search for a conference name where he his registered. But when the user enters some text in the form search input like "test" and click in "Search" it appears "Undefined property: Illuminate\Pagination\LengthAwarePaginator::$participants (View: /Users/john/projects/proj/resources/views/users/index.blade.php)". Do you know what can be the issue?
Code in he view:
<div class="tab-pane clearfix fade" id="myTickets" role="tabpanel" aria-labelledby="contact-tab">
<div class="d-flex justify-content-between">
<form method="get" class="clearfix w-75" method="POST" action="{{ route('user.searchRegistration') }}">
{{ csrf_field() }}
<div class="form-group col col-md-6 px-0">
<div class="input-group" data-provide="datepicker">
<input type='text' class="form-control" placeholder="Search Registrations"
name="search_registration"
value="{{old('search_registration')}}"/>
<button class="input-group-addon">Search</button>
</div>
</div>
</form>
<a href="{{route('user.cleanSearchRegistration')}}" class="btn btn-outline-primary"
id="cleanSearchRegistration">Clean Search</a>
</div>
#if(session('searchedRegistrations'))
#if(session('searchedRegistrations')->count() != null)
#foreach(session('searchedRegistrations') as $registration)
#foreach(session('searchedRegistrations')->participants as $participant)
#if(!empty($registration))
<li class="list-group-item">
<h5>{{optional($registration->conference)->name}}</h5>
#if ($registration->status == 'C')
<a href="{{route('conference.registrationInfo',
['id' => $registration->conference->id,
'slug' => $registration->conference->slug,
'regID'=> $registration->id])}}"
class="btn btn-primary ml-2"><i class="fa fa-file-pdf-o"></i> Registration document
</a>
#endif
#if ($participant->registration_type->certificate_available == 'Y')
<a href="{{route('conferences.certificateInfo',
[
'regID'=> $registration->id])}}"
class="btn btn-primary ml-2"><i class="fa fa-file-pdf-o"></i> Download certificate
</a>
#break
#endif
</li>
#endif
#endforeach
#endforeach
<div class="text-center d-flex justify-content-center mt-3">
{{session('searchedRegistrations')->fragment('searchRegistrations')->links("pagination::bootstrap-4")}}
</div>
#else
<div class="alert alert-info" role="alert">
<i class="material-icons">info</i>
<span>Your search didnt return any result.</span>
</div>
#endif
#else
<div class="d-flex mb-3">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" href="#nextConferences" data-toggle="tab" role="tab">Next
Conferences</a>
</li>
<li class="nav-item">
<a class="nav-link border" href="#PastRegistrations" data-toggle="tab" role="tab">Past
Conferences</a>
</li>
</ul>
</div>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active clearfix" id="nextConferences" role="tabpanel"
aria-labelledby="home-tab">
<ul class="list-group">
#foreach($nextRegistrations as $nextRegistration)
#foreach($nextRegistration->participants as $participant)
#if(!empty($nextRegistration->conference) || !empty($nextRegistration->conference->start_date))
<li class="list-group-item">
<h5>{{optional($nextRegistration->conference)->name}}</h5>
#if ($participant->registration_type->certificate_available == 'Y')
<a href="{{route('conferences.certificateInfo',
[
'regID'=> $nextRegistration->id])}}"
class="btn btn-primary ml-2"><i
class="fa fa-file-pdf-o"></i> Download Certificate</a>
#break
#endif
#if ($nextRegistration->status == 'C')
<a href="{{route('conferences.registrationInfo',
[
'regID'=> $nextRegistration->id])}}"
class="btn btn-primary ml-2"><i
class="fa fa-file-pdf-o"></i> Registration document
</a>
#endif
</li>
#endif
#endforeach
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$nextRegistrations->fragment('nextConferences')->links("pagination::bootstrap-4")}}
</div>
</div>
<div class="tab-pane fade show clearfix" id="pastConferences" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($pastRegistrations as $pastRegistration)
#foreach($pastRegistration->participants as $participant)
#if(!empty($pastRegistration->conference) || !empty($pastRegistration->conference->start_date))
<li class="list-group-item">
<h5>{{optional($pastRegistration->conference)->name}}</h5>
#if ($participant->registration_type->certificate_available == 'Y')
<a href="{{route('conferences.certificateInfo',['regID'=> $pastRegistration->id])}}"
class="btn btn-primary ml-2"><i
class="fa fa-file-pdf-o"></i> Download Certificate
</a>
#break
#endif
#if ($pastRegistration->status == 'C')
<a href="{{route('conferences.registrationInfo',
[
'regID'=> $pastRegistration->id])}}"
class="btn btn-primary ml-2"><i
class="fa fa-file-pdf-o"></i> Registration info
</a>
#endif
</li>
#endif
#endforeach
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$pastRegistrations->fragment('pastConferences')->links("pagination::bootstrap-4")}}
</div>
</div>
</div>
</div>
I assume session('searchedRegistrations') is the Pagination instance. There is no property named participants nor would there be any random properties (it is a container, not what it contains). I would imagine a model instance contained in the collection might have a participants property though.
#foreach(session('searchedRegistrations') as $registration)
#foreach(session('searchedRegistrations')->participants as $participant)
I am guessing that should be
#foreach($registration->participants as $participant)

Laravel: Change login layout error

I use the simple built-in php artisan make:auth authentication in laravel and I would like to change the default layout.
login.blade.php
#extends('layouts.default')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
default.blade.php
<!DOCTYPE html>
<html>
<head>
#include('includes.head')
</head>
<body>
#include('includes.sidebar')
<div id="main" class="row">
<div class = "content">
#yield('content')
</div>
</div>
<script src="full_calendar/lib/jquery-ui.js"></script>
<script src='full_calendar/lib/moment.min.js'></script>
<script src='js/bootstrap.min.js'></script>
<script src='js/sidebar.js'></script>
</body>
</html>
sidebar.blade.php
<nav class="navbar navbar-inverse sidebar" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-sidebar-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">{{ Auth::user()->name }}</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-sidebar-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Home<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-home"></span></li>
<li >Calendar->employees<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span></li>
<li >Calendar->employers<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span></li>
<li >Register<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-envelope"></span></li>
<li >Log out<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-envelope"></span></li>
<li >About<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-logout"></span></li>
<li class="dropdown">
Settings <span class="caret"></span><span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-cog"></span>
<ul class="dropdown-menu forAnimate" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Error message
ErrorException in 23932780504d5d1cb3d219486de49ace0b7f23c9.php line
11: Trying to get property of non-object (View:
C:\xampp\htdocs\laravel\resources\views\includes\sidebar.blade.php)
(View:
C:\xampp\htdocs\laravel\resources\views\includes\sidebar.blade.php)
(View:
C:\xampp\htdocs\laravel\resources\views\includes\sidebar.blade.php)
Why does this exception occur?
The issue in your code could be Auth::user()->name try dumping the value of Auth::user() (code is dd(Auth::user())) if it shows null that's the issue.
and in below code
<li >Calendar->employees<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span></li>
<li >Calendar->employers<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span></li>
Instead of Calendar->employees you should write {{ $Calendar->employees }} and same for Calendar->employers instead you should write {{ $Calendar->employers }} without {{...}} or {!!...!!} it will not print the variable values.

Categories