Laravel 8 Error: Attempt to assign property "id_gerai" on null - php

I building a page to insert rows into database tables using a HTML form. I created my view, model, controller, and route already and it return this error when i try to submit the form:
Attempt to assign property "id_gerai" on null
Here are the rest of the code
resources\views\dashboard\manajemen_donasi.blade.php
#extends('layouts.dashboard')
#section('title')
<title>KitaKenyang - Dashboard Admin</title>
#endsection
#section('nav_link')
<li class="nav-item active">
<a class="nav-link" href="/manajemen donasi">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Manajemen Donasi</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/manajemen penyimpanan">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Manajemen Penyimpanan</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/manajemen penyaluran">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Manajemen Penyaluran</span></a>
</li>
#endsection
#section('username')
Admin
#endsection
#section('content')
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800 text-center">Dashboard Manajemen Donasi</h1>
</div>
<div class="container-fluid">
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-success">Input Donasi</h6>
</div>
<div class="card-body">
<form action="#" method="post" class="probootstrap-form">
#csrf <!-- {{ csrf_field() }} -->
<div class="form-group">
<label for="id_user">ID Donatur</label>
<input type="text" class="form-control" id="id_user" name="id_user">
</div>
<div class="form-group">
<label for="tanggal">Tanggal Donasi</label>
<input type="date" class="form-control" id="tanggal" name="tanggal">
</div>
<div class="form-group">
<label for="id_kategori_barang">Kategori</label>
<input type="text" class="form-control" id="id_kategori_barang" name="id_kategori_barang">
<i>* dry staple: 1 | dehydrated food: 2 | canned food: 3 | frozen food: 4</i>
</div>
<div class="form-group">
<label for="id_kuantitas">Kuantitas</label>
<input type="text" class="form-control" id="kuantitas" name="kuantitas">
</div>
<div class="form-group">
<label for="id_nama_barang">Nama barang</label>
<input type="text" class="form-control" id="nama_barang" name="nama_barang">
</div>
<div class="form-group">
<label for="id_gerai">ID Gerai</label>
<input type="text" class="form-control" id="id_gerai" name="id_gerai">
</div>
<div class="form-group">
<input type="submit" class="btn btn-success btn-lg" id="submit" name="submit" value="Input">
</div>
</form>
</div>
</div>
</div>
<!-- /.container-fluid -->
#endsection
routes\web.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Models\Donasi;
/*
|--------------------------------------------------------------------------
| 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('/', 'PagesController#index');
Route::get('/beranda', 'PagesController#index');
Route::get('/tentang kami', 'PagesController#about');
Route::get('/berita', 'PagesController#news');
Route::get('/program', 'PagesController#program');
Route::get('/gerai donasi', 'PagesController#gerai');
Route::get('/login', 'PagesController#login');
Route::get('/register', 'PagesController#register');
Route::get('/kinerja organisasi', 'DashboardController#laporan_org');
Route::get('/donasi user', 'DashboardController#laporan_user');
Route::get('/profil user', 'DashboardController#profil_user');
Route::get('/manajemen donasi', 'DashboardController#manajemen_donasi');
Route::post('manajemen donasi', 'DashboardController#input_donasi');
Route::get('/manajemen penyimpanan', 'DashboardController#manajemen_penyimpanan');
Route::get('/manajemen penyaluran', 'DashboardController#manajemen_penyaluran');
App\Models\Donasi.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Donasi extends Model
{
use HasFactory;
protected $table = 'donasi';
protected $primaryKey = 'id';
protected $fillable = [
'id_user',
'id_kategori_barang',
'id_gerai',
'nama_barang',
'kuantitas',
'tanggal',
];
public $timestamps = false;
}
app\Http\Controllers\DashboardController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Program;
use App\Models\DonasiDalamPenyimpanan;
use App\Models\TotalDonasi;
use App\Models\TotalDonatur;
use App\Models\Donasi;
class DashboardController extends Controller
{
public function laporan_org()
{
$totaldonatur = TotalDonatur::all();
$totaldonasi = TotalDonasi::all();
$program = Program::all();
return view('dashboard.laporan_org', compact('program', 'totaldonasi', 'totaldonatur'));
}
public function laporan_user()
{
return view('dashboard.laporan_user');
}
public function profil_user()
{
return view('dashboard.profil_user');
}
public function manajemen_donasi()
{
return view('dashboard.manajemen_donasi');
}
public function manajemen_penyimpanan()
{
$penyimpanan = DonasiDalamPenyimpanan::all();
return view('dashboard.manajemen_penyimpanan', compact('penyimpanan'));
}
public function manajemen_penyaluran()
{
$program = Program::all();
return view('dashboard.manajemen_penyaluran', compact('program'));
}
public function input_donasi(Request $request)
{
$donasi = new Donasi;
$donasi->id_user = $request->input('id_user');
$donasi->tanggal = $request->input('tanggal');
$donasi->id_kategori_barang = $request->input('id_kategori_barang');
$donasi->kuantitas = $request->input('kuantitas');
$donasi->nama_barang = $request->input('nama_barang');
$donasiModel->id_gerai = $request->input('id_gerai');
$donasi->save();
}
}

Related

Laravel Undefined variable: todos (View: /var/www/html/resources/views/content/apps/todo/app-todo.blade.php)

I am currently trying to display todos in my app-todo view, but I keep getting the error mentioned in the title.
In my controller I have:
public function index()
{
$todos = Todo::all();
return view('content.apps.todo.app-todo', ['todos' => $todos]);
}
and in my app-todo:
<div class="todo-task-list-wrapper list-group">
<ul class="todo-task-list media-list" id="todo-task-list">
#foreach($todos as $todo)
<li class="todo-item">
<div class="todo-title-wrapper">
<div class="todo-title-area">
<i data-feather="more-vertical" class="drag-icon"></i>
<div class="title-wrapper">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="customCheck1" />
<label class="form-check-label" for="customCheck1"></label>
</div>
<span class="todo-title">Drink more water</span>
</div>
</div>
<div class="todo-item-action">
<div class="badge-wrapper me-1">
<span class="badge rounded-pill badge-light-primary">Team</span>
</div>
<small class="text-nowrap text-muted me-1">Aug 08</small>
<div class="avatar">
<img
src="{{asset('images/portrait/small/avatar-s-4.jpg')}}"
alt="user-avatar"
height="32"
width="32"
/>
</div>
</div>
</div>
</li>
#endforeach
I have tried changing the code in the controller to return view('content.apps.todo.app-todo')->with(['todos' => $todos]); and using compact('todos'); ,but I get the same error.
Update:
The model is the following:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Todo extends Model
{
protected $fillable = ['todoTitleAdd','task_assigned','task_due-date','task_tag', 'task_desc'];
}
and the web.php route:
Route::resource('todos', TodoController::class);
public function index(){
$todos = Todo::all();
return view('content.apps.todo.app-todo',compact('todos'));
}

Route [admin.editcategory] not defined

Hello Everyone I am new in laravel. I just started to watch a series of ecommerce from youtube.
In the series at the 15th video , when editing the category i did as same as the youtuber did. But there is an error. Please help me anyone.
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [admin.editcategory] not defined.
(View: C:\xampp\htdocs\Laravel\Xencommerce\resources\views\livewire\admin\admin-category-component.blade.php)
Here is my web.php codes
<?php
use App\Http\Livewire\HomeComponent;
use App\Http\Livewire\ShopComponent;
use App\Http\Livewire\CartComponent;
use App\Http\Livewire\CheckoutComponent;
use App\Http\Livewire\ContactComponent;
use App\Http\Livewire\AboutComponent;
use App\Http\Livewire\DetailsComponent;
use App\Http\Livewire\CategoryComponent;
use App\Http\Livewire\HeaderSearchComponent;
use App\Http\Livewire\SearchComponent;
use App\Http\Livewire\User\UserDashboardComponent;
use App\Http\Livewire\Admin\AdminDashboardComponent;
use App\Http\Livewire\Admin\AdminCategoryComponent;
use App\Http\Livewire\Admin\AdminAddCategoryComponent;
use App\Http\Livewire\Admin\AdminEditCategoryComponent;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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('/',HomeComponent::class);
Route::get('/shop',ShopComponent::class);
Route::get('/cart',CartComponent::class)->name('product.cart');
Route::get('/checkout',CheckoutComponent::class);
Route::get('/contact',ContactComponent::class);
Route::get('/about',AboutComponent::class);
Route::get('/product/{slug}',DetailsComponent::class)->name('product.details');
Route::get('/product-category/{category_slug}',CategoryComponent::class)->name('product.category');
Route::get('/search',SearchComponent::class)->name('product.search');
// Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
// return view('dashboard');
// })->name('dashboard');
// For User and Customer
Route::middleware(['auth:sanctum','verified'])->group(function(){
Route::get('/user/dashboard',UserDashboardComponent::class)->name('user.dashboard');
});
// For Admin
Route::middleware(['auth:sanctum','verified','authadmin'])->group(function(){
Route::get('/admin/dashboard',AdminDashboardComponent::class)->name('admin.dashboard');
Route::get('/admin/categories',AdminCategoryComponent::class)->name('admin.categories');
Route::get('/admin/categories/add',AdminAddCategoryComponent::class)->name('admin.addcategory');
Route::get('/admin/categories/edit/{category_slug}',AdminEditCategoryComponent::class)->name('admin.editcategory');
});
Here is my AdminCategoryComponent.php codes
<?php
namespace App\Http\Livewire\Admin;
use App\Models\Category;
use Livewire\Component;
use Livewire\WithPagination;
class AdminCategoryComponent extends Component
{
use WithPagination;
public function render()
{
$categories = Category::paginate(5);
return view('livewire.admin.admin-category-component',['categories'=>$categories])->layout('layouts.base');
}
}
Here is admin-category-component.blade.php
<div>
<style>
nav svg{
height: 20px;
}
nav .hidden{
display: block !important;
}
</style>
<div class="container" style="padding: 30px 0;">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
All Categories
</div>
<div class="col-md-6">
Add New Category
</div>
</div>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Category Name</th>
<th>Slug</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($categories as $category)
<tr>
<th>{{$category->id}}</th>
<th>{{$category->name}}</th>
<th>{{$category->slug}}</th>
<th>
<i class="fa fa-edit fa-2x"></i>
<!-- <i class="fa fa-trash fa-2x"></i> -->
</th>
</tr>
#endforeach
</tbody>
</table>
{{$categories->links()}}
</div>
</div>
</div>
</div>
</div>
</div>
Here is AdminEditCategoryComponent.php
<?php
namespace App\Http\Livewire\Admin;
use App\Models\Category;
use Livewire\Component;
use Illuminate\Support\Str;
class AdminEditCategoryComponent extends Component
{
public $category_slug;
public $category_id;
public $name;
public $slug;
public function mount($category_slug)
{
$this->category_slug = $category_slug;
$category = Category::where('slug',$category_slug)->first();
$this->category_id = $category->id;
$this->name = $category->name;
$this->slug = $category->slug;
}
public function generateslug()
{
$this->slug = Str::slug($this->name);
}
public function updateCategory()
{
$category = Category::find($this->category_id);
$category->name = $this->name;
$category->slug = $this->slug;
$category->save();
session()->flash('message','Your category has beed updated successfully');
}
public function render()
{
return view('livewire.admin.admin-edit-category-component')->layout('layouts.base');
}
}
Here is my admin-edit-category-component.blade.php
<div>
<div class="container" style="padding: 30px 0;">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
Edit Category
</div>
<div class="col-md-6">
All Categories
</div>
</div>
</div>
<div class="panel-body">
#if(Session::has('message'))
<div class="alert alert-success" role="alert">{{Session::get('message')}}</div>
#endif
<form class="form-horizontal" wire:submit.prevent="updateCategory">
<div class="form-group">
<label class="col-md-4 control-label">Category Name</label>
<div class="col-md-4">
<input type="text" placeholder="Category Name" class="form-control input-md" wire:model="name" wire:keyup="generateslug">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Category Slug</label>
<div class="col-md-4">
<input type="text" placeholder="Category Slug" name="" class="form-control input-md" wire:model="slug">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-primary">Update Category</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Change the href in admin-category-component.blade.php to href="'/admin/categories/edit/{{$category->slug}}" and remove the route name .
And it should be fine.

I am trying to pass the id of a user from the users table from an authenticated users profile

I am trying to pass the id of a user from the users table from an authenticated users profile in a chat application I am trying to build. I keep getting SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'recever' cannot be null (SQL: insert into chats (message, sender, recever, updated_at, created_at) values (hi, 2, ?, 2021-05-24 21:13:20, 2021-05-24 21:13:20)). The recever column is always empty because I couldn't pass the id value of the user.
My Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Chat;
use App\Models\typing;
use App\Models\User;
use Auth;
use DB;
use URL;
use Illuminate\Support\Str;
class ChatController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function store(Request $request, $id=null){
$auth_id = Auth::user()->id;
$user = DB::table('users')->where('id', $id)->first();
$chat = new Chat;
$chat->message = $request->message;
$chat->sender = $auth_id;
$chat->recever = $user->id;
$chat->save();
typing::where('recever',$chat->recever)
->where('sender', $chat->sender)
->update(['check_status' => 0]);
return back();
}
}
My Blade file
#extends('layouts.app')
#section('content')
<?php
$recever=Route::input('id');
$id=Auth::id();
$user = DB::table('users')->where('id', $recever)->first();
?>
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-primary">
<div class="panel-heading" style="height:40px;">
<div class="pull-left">
<a onclick="seenUpdate()" style="color:#fff;text-decoration:none; margin-left: 12px;" href="{{URL::to('/')}}">
<span class="glyphicon glyphicon-comment">
</span> <b class="smsnum"id="smsnum"></b> Message
</a>
<a style="color:#fff;text-decoration:none; margin-left: 12px;" href="{{URL::to('/users')}}">
<span class="glyphicon glyphicon-user"></span> User
</a>
</a>
<a style="color:#fff; text-decoration:none; margin-left: 12px;" href="{{URL::to('/')}}">
<span class="glyphicon glyphicon-search"></span> Search
</a>
</div>
<div class="pull-right">
{{$user->name}}
</div>
</div>
<div class="panel-body" id="scrolltoheight">
<ul class="chat">
<div id="chat-message">
</div>
</ul>
</div>
<div class="typing"><p id="typing"></p></div>
<div class="panel-footer">
<form id="message-submit" action="{{ url('/send-message/'.$user->id) }}" method="post"> {{ csrf_field()}}
<div class="input-group">
<input onkeyup="typing()" id="message" type="text" name="message" required class="form-control input-sm" placeholder="Type your message here..." />
<span class="input-group-btn">
<input type="submit" class="btn btn-warning btn-sm" id="btn-chat"value="Send"/>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
My Home controller that holds the home.blade.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Chat;
use DB;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
public function allmessage()
{
return view('allmessage');
}
function jsonResponse(){
$user = DB::table('chats')->get();
return response()->json($user);
}
}
You are trying to pass all of the model, instead you should pass only the id, try this:
//$chat->recever = $user;
$chat->recever = $user->id;
Also in your blade change this:
<form id="message-submit" action="{{ url('/send-message') }}" method="post">
To this:
<form id="message-submit" action="{{ url('/send-message/'.$user->id) }}" method="post">
The reason for this change is you are not passing the user of id, so it returns as null.

Error 404 on a view that exists on routes. The URL exists as well as the view but it keeps returning error 404

I am getting an error 404 from a view that actually exists in my routes.
This is the view where I select the data from (sidebar.blade.php)
<div class="col-xl-3 col-lg-3 col-sm-12 col-xs-12 sidebar-shop-left">
<div class="product-categori">
<div class="search-product">
<form action="#">
<input class="form-control" placeholder="Search here..." type="text">
<button type="submit"> <i class="fa fa-search"></i> </button>
</form>
</div>
<div class="filter-sidebar-left">
<div class="title-left">
<h3>Categories</h3>
</div>
<div class="list-group list-group-collapse list-group-sm list-group-tree" id="list-group-men" data-children=".sub-men">
#foreach($categories as $cat)
<div class="list-group-collapse sub-men">
<a class="list-group-item list-group-item-action" href="#{{$cat->id}}" data-toggle="collapse" aria-expanded="true" aria-controls="sub-men1">{{$cat->name}}
</a>
<div class="collapse hide" id="{{$cat->id}}" data-parent="#list-group-men">
#foreach($cat->categories as $subcat)
#if($subcat->status==1)
<div class="list-group">
{{$subcat->name}}
</div>
#endif
#endforeach
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
This my routes file i.e (web.php).
// use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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!
|
*/
// All Routes after Login
Route::group(['middleware'=>['frontlogin']],function(){
Route::get('/view-job','frontController#view');
Route::match(['get', 'post'], '/browse', 'frontController#browse');
Route::get('/resume/{url}','ResumeController#resumes');
// Resume Detail Page
Route::get('/resume/{id}','ResumeController#resume');
});
Route::match(['get', 'post'], '/how', 'frontController#how');
Route::get('/logout', 'AdminController#logout');
This is the controller of the view file frontController.blade.php (browse_categories.blade.php). The function is browse()
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redirect;
use App\Category;
use App\Country;
use App\Enquiry;
use App\Resume;
use App\User;
use App\Job;
use Validator;
use Auth;
use Session;
use Image;
use DB;
class frontController extends Controller
{
public function browse(){
$title='Browse Categories';
$resume = Resume::get();
foreach($resume as $key => $val){
$category_name = Category::where(['id' => $val->category_id])->first();
$resume[$key]->category_name = $category_name->name;
}
$resume = json_decode(json_encode($resume));
// echo "<pre>"; print_r($resume); die;
$categories_menu = "";
$categories = Category::with('categories')->where(['parent_id' => 0])->get();
$categories = json_decode(json_encode($categories));
return view('pages.browse_categories')->with(compact('categories_menu', 'categories', 'resume'), 'title', $title);
}
}
This is the view file I get the error 404 (detail.blade.php)
#section('content')
<!-- Start All Title Box -->
<div class="all-title-box">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>Details</h2>
<!-- <ul class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Browse</li>
</ul> -->
</div>
</div>
</div>
</div>
<!-- End All Title Box -->
<!-- Start Shop Page -->
<div class="shop-box-inner">
<div class="container">
<div class="row">
#include('layouts.frontLayouts.frontSidebar')
<div class="col-xl-9 col-lg-9 col-sm-12 col-xs-12 shop-content-right">
<div class="right-product-box">
<div class="product-item-filter row">
<div class="col-12 col-sm-8 text-center text-sm-left">
<!-- <div class="toolbar-sorter-right">
<span>Sort by </span>
<select id="basic" class="selectpicker show-tick form-control" data-placeholder="$ USD">
<option data-display="Select">Nothing</option>
<option value="1">Popularity</option>
<option value="2">High Price → High Price</option>
<option value="3">Low Price → High Price</option>
<option value="4">Best Selling</option>
</select>
</div> -->
<p>Profile Details</p>
</div>
<div class="col-12 col-sm-4 text-center text-sm-right">
<!-- <ul class="nav nav-tabs ml-auto">
<li>
<a class="nav-link" href="#grid-view" data-toggle="tab"> <i class="fa fa-th"></i> </a>
</li>
<li>
<a class="nav-link active" href="#list-view" data-toggle="tab"> <i class="fa fa-list-ul"></i> </a>
</li> -->
</ul>
</div>
</div>
<div class="row product-categorie-box">
<div class="tab-content">
<!-- <div role="tabpanel" class="tab-pane fade" id="grid-view">
<div class="row">
<div class="col-sm-6 col-md-6 col-lg-4 col-xl-4">
#foreach($resume as $res)
<div class="products-single fix">
<div class="box-img-hover">
#if(!empty($res->image))
<img src="{{ asset('/images/uploads/passport/small/'.$res->image) }}" class="img-fluid" alt="Image">
#endif
<div class="mask-icon">
<a class="cart" href="{{ url('/resume/'.$res->id) }}">View Profile</a>
</div>
</div>
<div class="why-text">
<h4>{{ $res->user_name}}</h4>
<h5> {{ $res->category_name}}</h5>
</div>
</div>
</div>
#endforeach
</div>
</div> -->
<div role="tabpanel" class="tab-pane fade show active" id="list-view">
<div class="list-view-box">
<div class="row">
<div class="col-sm-6 col-md-6 col-lg-4 col-xl-4">
<div class="products-single fix">
<div class="box-img-hover">
<!-- <div class="type-lb">
<p class="sale">Sale</p>
</div> -->
<img src="{{ asset('/images/uploads/passport/medium/'.$resumeDetails->image) }}" class="img-fluid" alt="Image">
<!-- <div class="mask-icon">
<ul>
<li><i class="fas fa-eye"></i></li>
<li><i class="fas fa-sync-alt"></i></li>
<li><i class="far fa-heart"></i></li>
</ul>
</div> -->
</div>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-8 col-xl-8">
<div class="why-text full-width">
<h4>{{ $resumeDetails ->user_name }}</h4>
<h5>Expected Salary ${{ $resumeDetails->salary}}</h5>
<p>Staff Information: {{ $resumeDetails->summary}}</p>
<a class="btn hvr-hover" href="#">Message</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End Shop Page -->
#endsection
This is the controller of the view file where I get the error 404 i.e detail.blade.php (Resume Controller) The function is resume
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
use App\Resume;
use App\Category;
use App\Country;
use App\User;
use Auth;
use Session;
use Image;
use DB;
class ResumeController extends Controller
{
public function resumes($url=null){
$categoryCount = Category::where(['url'=>$url,'status'=>1])->count();
if($categoryCount==0){
abort(404);
}
$categories = Category::with('categories')->where(['parent_id' => 0])->get();
$categoryDetails = Category::where(['url'=>$url])->first();
if($categoryDetails->parent_id==0){
$subCategories = Category::where(['parent_id'=>$categoryDetails->id])->get();
$subCategories = json_decode(json_encode($subCategories));
foreach($subCategories as $subcat){
$cat_ids[] = $subcat->id;
}
$resumeAll = Resume::whereIn('resume.category_id', $cat_ids)->where('resume.status','1')->orderBy('resume.id','Desc');
$breadcrumb = "<a href='/'>Home</a> / <a href='".$categoryDetails->url."'>".$categoryDetails->name."</a>";
}else{
$resumeAll = Resume::where(['resume.category_id'=>$categoryDetails->id])->where('resume.status','1')->orderBy('resume.id','Desc');
$mainCategory = Category::where('id',$categoryDetails->parent_id)->first();
$breadcrumb = "<a href='/'>Home</a> / <a href='".$mainCategory->url."'>".$mainCategory->name."</a> / <a href='".$categoryDetails->url."'>".$categoryDetails->name."</a>";
}
$resumeAll = $resumeAll->paginate(6);
// $resumeAll = json_decode(json_encode($resumeAll));
// echo "<pre>"; print_r($resumeAll); die;
return view('pages.listing')->with(compact('categories','resumeAll','categoryDetails','url','breadcrumb'));
}
public function resume($id = null){
// Show 404 Page if resume is disabled
$resumeCount = Resume::where(['id'=>$id,'status'=>1])->count();
if($resumeCount==0){
abort(404);
}
// Get resume Details
$resumeDetails = Resume::with('experience')->where('id',$id)->first();
$relatedResumes = Resume::where('id','!=',$id)->where(['category_id' => $resumeDetails->category_id])->get();
$categories = Category::with('categories')->where(['parent_id' => 0])->get();
$categoryDetails = Category::where('id',$resumeDetails->category_id)->first();
if($categoryDetails->parent_id==0){
$breadcrumb = "<a href='/'>Home</a> / <a href='".$categoryDetails->url."'>".$categoryDetails->name."</a> / ".$resumeDetails->user_name;
}else{
$mainCategory = Category::where('id',$categoryDetails->parent_id)->first();
$breadcrumb = "<a style='color:#333;' href='/'>Home</a> / <a style='color:#333;' href='/resume/".$mainCategory->url."'>".$mainCategory->name."</a> / <a style='color:#333;' href='/resume/".$categoryDetails->url."'>".$categoryDetails->name."</a> / ".$resumeDetails->user_name;
}
$meta_title = $resumeDetails->user_name;
$meta_description = $resumeDetails->summary;
$meta_keywords = $resumeDetails->user_name;
return view('pages.detail')->with(compact('resumeDetails','categories','relatedResumes','meta_title','meta_description','meta_keywords','breadcrumb'));
}
public function deleteResume($id = null){
Resume::where(['id'=>$id])->delete();
return redirect()->back()->with('flash_message_success', 'Resume has been deleted successfully');
}
}
Overall Solution: Replace url('/resume/'.$res->id) with action('ResumeController#resume', $resume). You may have to rearrange the order of your two url same routes. I highly recommend that you make them separate urls or remove the parameter from the one.
Solution to Current Problem: You can run php artisan route:list and it'll give you an output of every single valid route. From there, you'll be able to see the issue.
Side note: You can use any instead of match.

Laravel 5: how to do multi threaded comments

I am using Laravel Commentable package which uses Nested Sets pattern with Baum.
I have managed to allow users to make comments on posts but they're not threaded, each comment has depth set to zero in the database.
So I'm wondering how does one go about making multi threaded comments like reddit for example?
These are my tables
users: id, name, email...
posts: id, user_id, subreddit_id...
comments: id, body, parent_id, lft, rgt, depth, commentable_id, commentable_type, user_id
My Models (Comment and User)
class Comment extends Model
{
use Commentable;
public function commentable()
{
return $this->morphTo();
}
public function user() {
return $this->belongsTo('App\User');
}
public function posts() {
return $this->belongsTo('App\Post');
}
}
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
public function posts() {
return $this->hasMany('App\Post');
}
public function comments() {
return $this->hasMany('App\Comment');
}
}
This is how I'm submitting comments in PostsController
public function createComment($id) {
$post = Post::with('user.votes')->with('subreddit.moderators')->where('id', $id)->first();
$comment = new Comment;
$comment->body = Input::get('comment');
$comment->user_id = Auth::id();
$post->comments()->save($comment);
}
And this is the view
<div class="post-comments">
{!! Form::open(['route' => ['comment', $post]]) !!}
<div class="form-group">
<label for="comment">Your Comment</label>
<textarea name="comment" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-default">Send</button>
{!! Form::close() !!}
<div class="comments-nav">
<ul class="nav nav-pills">
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
there are {{ count($comments) }} comments <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Best</li>
<li>Hot</li>
</ul>
</li>
</ul>
</div>
<div class="row">
<div class="media">
<!-- first comment -->
#foreach($comments as $comment)
<div class="media-heading">
<button class="btn btn-default btn-xs" type="button" data-toggle="collapse" data-target="#{{ $comment->id }}" aria-expanded="false" aria-controls="collapseExample"><span class="glyphicon glyphicon-minus" aria-hidden="true"></span></button> <span class="label label-info">12314</span> {{ $comment->user->name }} 12 hours ago
</div>
<div class="panel-collapse collapse in" id="{{ $comment->id }}">
<div class="media-left">
<div class="vote-wrap">
<div class="vote up">
<i class="glyphicon glyphicon-menu-up"></i>
</div>
<div class="vote inactive">
<i class="glyphicon glyphicon-menu-down"></i>
</div>
</div>
<!-- vote-wrap -->
</div>
<!-- media-left -->
<div class="media-body">
<p>{{ $comment->body }}</p>
<div class="comment-meta">
<span>delete</span>
<span>report</span>
<span>hide</span>
<span>
<a class="" role="button" data-toggle="collapse" href="#replyCommentT" aria-expanded="false" aria-controls="collapseExample">reply</a>
</span>
<div class="collapse" id="replyCommentT">
<form>
<div class="form-group">
<label for="comment">Your Comment</label>
<textarea name="comment" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-default">Send</button>
</form>
</div>
</div>
<!-- comment-meta -->
</div>
</div>
<!-- comments -->
#endforeach
</div>
<!-- first comment -->
</div>
</div>
<!-- post-comments -->
I haven't used Laravel Commentable package, but the docs look pretty good.
I believe you need use Commentable; on your Post model and not your Comment model.
It looks like your Comment model needs to extend Baum\Node and not Model
Then what you have should work.
$post = Post::with('user.votes')->with('subreddit.moderators')->where('id', $id)->first();
$comment = new Comment;
$comment->body = Input::get('comment');
$comment->user_id = Auth::id();
$post->comments()->save($comment);
// or you could do
$comment->makeChildOf($post);
To make a comment on a comment, it looks like you do something like this. I would probably make a CommentsController.
public function addComment(Request $request){
$parent = Comment::find(Input::get('parent_id'));
$comment = new Comment;
$comment->body = Input::get('comment');
$comment->user_id = Auth::id();
$comment->makeChildOf($parent);
}
The Relations, Root and Leaf scopes, Accessing the ancestry/descendancy chain section of the docs have several examples on how to then retrieve the comments for comments.
Edit
It looks like the Comment model in the package already extends the Baum\Node so you don't need to do that. In order to use this package, it looks like you need to use his Comment model. I am sure you could use his model as a base and roll your own.
You could do something like this. You would have to set up a route.
<div class="collapse" id="replyCommentT">
{!! Form::open(['route' => ['comment', $comment]]) !!}
<input type="hidden" name="parent_id" value="{{ $comment->id }}"/>
<div class="form-group">
<label for="comment">Your Comment</label>
<textarea name="comment" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-default">Send</button>
{!! Form::close() !!}
</div>

Categories