I got an error when I access menu, that show
Missing required parameters for [Route: bus.edit] [URI: bus/{bu}/edit]
.
Code for view from button
<a href="{{ route('bus.edit', ['bus' => $row["bus_id"]]) }}" class="btn btn-sm btn-warning">
Routes
Route::resource('bus', 'BusController')->middleware('auth');
For controller
public function index()
{
$data['title'] = "Buses";
$data['menu'] = 1;
$buses = DB::table('buses')
->join('brands', 'buses.brand_id', '=', 'brands.brand_id')
->get()->toArray();
$data['buses'] = json_decode(json_encode($buses), true);
$data['no'] = 1;
return view('bus.index', $data);
}
public function edit($id)
{
$data['title'] = "Edit Bus";
$data['menu'] = 1;
$data['bus'] = Bus::find($id);
$data['brands'] = Brand::all();
return view('bus.edit', $data);
}
As the error says, you need to pass a single parameter called {bu},
So change it to :
{{ route('bus.edit', ['bu' => $row["bus_id"]]) }}
Or,
{{ route('bus.edit', $row["bus_id"]) }}
Since the system for plural/singular is broken for this word, bus, in 8.x you can specifically tell the resource what the route parameter should be named:
Route::resource('bus', 'BusController')
->parameters(['bus' => 'bus'])
->middleware('auth');
This would make the route parameter bus instead of bu. Then the call to the route helper you currently have would work.
Related
Missing required parameters for [Route: listele] [URI: {language}/{slug}] [Missing parameters: language, slug]. (View: C:\xampp\htdocs\efsane\resources\views\product\product.blade.php)
What is the reason I am getting such an error?
Blade file
#foreach ($categories as $p)
{{$p->name}}
#endforeach
Route
Route::group(['prefix' => '{language}' ], function(){
Route::get('/{slug}' , 'App\Http\Controllers\ProductController#category')->name('listele');
});
My Controller
public function category($slug)
{
$category = Category::where('slug' , $slug )->first();
$data['category'] = $category;
$data['categories'] = Category::inRandomOrder()->get();
$data['posts'] = Post::where('category_id' , $category->id)->orderBy('id', 'DESC')->paginate(10);
return view('product.kategorilist' , $data );
}
You will need to put the route paramter values in an array and put that array in your route method route('listele', [app()->getLocale(), $p->slug]).
You will also need to access the category slug from the object so you have to use $p->slug.
#foreach ($categories as $p)
<a href="{{route('listele', [app()->getLocale(), $p->slug])}}"
class="list-group-item">{{$p->name}}</a>
#endforeach
--EDIT
There was also the </a> endtag missing
--EDIT2
Your controller method defines only the $slug parameter. But you are defining a prefix in your route for the $language parameter and the route itself defines the $slug parameter.
You have to simply add another parameter called $language to your controller method.
public function category($language, $slug) { .... }
In your case the language value was assigned to the slug variable and therefore no categroy was found (null is set). If you want to access an attribute of a null object you have a problem.
I would add a check to ensure $category is not null.
public function category($language, $slug) {
$category = Category::where('slug' , $slug )->first();
if(is_null($category)){
return redirect()->back();
}
....
}
I want www.example.com/shop/slug/productname
I have a error :
Missing required parameters for [Route: shop.show] [URI:
shop/{slug}/{productName}]. (0)
my route for each product
{{ route('shop.show',[$product->slug,$product->name]) }}
and is my shopcontroller
public function show($slug,$productName)
{
$productslug = Product::where('slug',$slug)->firstOrFail();
$productname = Product::where('name',$productName)->firstOrFail();
$mightAlsoLike = Product::where('slug', '!=' ,$slug)-
>MightAlsoLike()->get();
return view('front.product')
->with('product', $productname)
->with('product', $productslug)
->with( 'mightAlsoLike', $mightAlsoLike);
}
and is my web.php :
Route::get('/shop/{slug}/{productName}', 'ShopController#show')->name('shop.show');
You have to pass key in case of multiple route parameters.
Route::get('/shop/{slug}/{productName}', 'ShopController#show')->name('shop.show');
And use route like this:
{{ route('shop.show',['slug'=>$product->slug,'productName'=>$product->name]) }}
This is My Controller.
public function show(Posts $posts)
{
$page = Posts::find($posts->id);
//dd($page);
return view('web_views.index',['page' => $page]);
}
This is my view page
<h4>{{$page->post_titile}}</h4>
It's better to use Route-Model Binding I think.
Your route (if you are using resource route, it's already done):
Route::get('posts/{post}', 'PostController#show); // domain.tld/posts/1
Your method should look like this:
public function show(Post $post)
{
return view('web_views.index',compact('post'));
}
In your view:
<h4>{{ $post->post_titile }}</h4>
May be $posts->id you are passing, has no result in database so you need to check it by using if-statement
public function show(Posts $posts)
{
$page = Posts::find($posts->id);
if($page == null){
$page = ['post_title' => 'Not Available'];
}
return view('web_views.index',['page' => $page]);
}
I believe this error is because of not finding data for an ID into database. So if as per above script will pass the fetched data to view otherwise it will push an item into $page array.
I'm looking to fetch unique values from a table in my database and pass the company name into my view as options in a drop down list within a form.
The function in my controller looks like this:
public function index()
{
$id = Auth::user()->id;
$admin = Admin::find($id);
$companies = DB::table('vacancies')->distinct()->select('company')->get()->toArray();
return view('admin')->with('admin',$admin)->with('companies',$companies);
}
And my view looks like this:
<div class="form-group">
#foreach ($companies as $company)
{{ Form::label('Select Company')}}
{{ Form::select('companies', $company->company, ['class'=>'form-control', 'placeholder'=>'Please select ...']) }}
#endforeach
</div>
I'm getting the following error:
Invalid argument supplied for foreach()
If I try {{dd($companies}} I can see an array is being passed through to the view OK. This array looks like this:
array:353[
0 => {#274 ▼
+"company": "Example company name"
}......
]
Ditching the loop and reverting back to:
<div class="form-group">
{{ Form::label('Select Company')}}
{{ Form::select('companies', $companies, ['class'=>'form-control', 'placeholder'=>'Please select ...']) }}
</div>
causes another error to be thrown which states:
htmlspecialchars() expects parameter 1 to be string, object given
Where am I going wrong here?
In your controller
public function index()
{
$id = Auth::user()->id;
$admin = Admin::find($id);
$companies = DB::table('vacancies')->distinct()->pluck('company')->toArray();
return view('admin')->with('admin',$admin)->with('companies',$companies);
}
Fllow as per below
your index function must be like below
public function index()
{
$id = Auth::user()->id;
$admin = Admin::find($id);
$companies = DB::table('vacancies')->distinct()->pluck('company')->toArray();
return view('admin')->with('admin',$admin)->with('companies',$companies);
}
your view must me like below
<div class="form-group">
{{ Form::label('Select Company')}}
{{ Form::select('companies', $companies, ['class'=>'form-control', 'placeholder'=>'Please select ...']) }}
</div>
let me know if any
I'm building a backend for my website in Laravel. I need only few text boxes to populate a template. So far I've managed to do that, but every time I pass a value to a template I see also all previous values, not only the last one.
So for example if I'm editing slider title, I see also all previous slider titles - I want to see only last one.
My controler:
public function store()
{
$input = Input::all();
homepage::create([
'slider_title' => $input['slider_title'],
]);
return Redirect::to('/');
}
Part of view responsible for displaying slider title:
#foreach ($homepage as $home)
{{$home->slider_title}}
#endforeach
View for user input in admin:
{{ Form::open(['url' => '/admin']) }}
<div>
{{ Form::label('slider_title', 'Slider title:') }}
{{ Form::text('slider_title') }}
</div>
<div>
{{ Form::submit('Change a slider title') }}
</div>
{{ Form::close() }}
Route for admin:
Route::post('/admin', 'AdminController#store');
Route for main page:
Route::get('/', 'PageController#home');
PageController home method:
public function home()
{
$homepage = Homepage::all();
return View::make('home')->with('homepage',$homepage);
}
I tried changing PageControl with:
$homepage = Homepage::orderBy('id', 'desc')->first();
but I'm getting this error:
ErrorException: Trying to get property of non-object on my view page
public function home()
{
$homepage = Homepage::all();
return View::make('home')->with('homepage',$homepage);
}
You are seeing all slides because you are selecting all of them:
$homepage = Homepage::all();
This should give you the last one:
$homepage = Homepage::orderBy('id', 'desc')->first();
or
$homepage = Homepage::orderBy('created_at', 'desc')->first();
Remember that now you are getting only one result and you cannot use foreach anymore:
foreach ($homepage as $home)
You can refer to it directly:
$homepage->slider_title
If you still want to return an array to use foreach, this is an option:
$homepage = array( Homepage::orderBy('created_at', 'desc')->first() );