Please share the appropriate section of your routes file and the html section with the links!
Show and Edit is showing the same despite it being different view in Controller
Hi,
I am busy with a CRUD system and strange enough my views are messed up. Each view is different, the controller is pointing to them:
/**
* Display the specified resource.
*
* @param \App\Form $form
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return view('forms.show');
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Form $form
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
return view('forms.edit');
}
But the edit page and show page are displaying the same view?? The blade pages are different showing an eye icon for show and a pencil for the edit, but the show blade page keeps showing no matter what route I use /client-form/edit or /show
Is this a bug or am I missing something very simple
Also if I change anything on the show blade it does the same on the edit page... WHAT!!! Also my Route is as follows:
Route::resource('/client-form', 'FormController');
Links: http://localhost/upload/public/client-form/edit http://localhost/upload/public/client-form/show
Html:
SHOW
@extends('layouts.app')
@section('content')
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
@include('partials.template.sidebar')
<!-- End of Sidebar -->
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Topbar -->
@include('partials.template.navbar')
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><i class="text-success fas fa-eye"></i> Forms</h1>
<a href="{{ URL::previous() }}" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-angle-double-left fa-sm text-white-50"></i> Back</a>
</div>
<!-- Content Row -->
<div class="row">
<div class="col-md-12 col-xs-12 col-lg-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Fill in the fields below...</h6>
</div>
<div class="card-body">
<form action="" method="">
<div class="row">
<div class="col-md-2">
<label for="job_description">Job No</label>
<input class="form-control" name="job_description" type="text" disabled value="001">
</div>
<div class="col-md-2">
<label for="company">Company</label>
<select class="form-control" name="company" id="company">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="brand">Brand</label>
<select class="form-control" name="brand" id="brand">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-4">
<label for="type_communication">Type of Communication</label>
<select class="form-control" name="type_communication" id="type_communication">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="user_id">User</label>
<input class="form-control" name="user_id" type="text" disabled value="{{Auth::user()->name}}">
</div>
</div>
<div class="row pt-3">
<div class="col-md-4">
<label for="channels">Channels</label>
<select class="js-tags form-control" name="channels[]" multiple="multiple">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="col-md-2">
<label for="frequencies">Frequency</label>
<select class="form-control" name="frequencies" id="frequencies">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="">Start Date</label>
<input class="form-control" name="start_date" type="text" data-provide="datepicker">
</div>
<div class="col-md-2">
<label for="">End Date</label>
<input class="form-control" name="end_date" type="text" data-provide="datepicker">
</div>
<div class="col-md-2">
<label for="media_types">Media Types</label>
<select class="form-control" name="media_types" id="media_types">
<option value="">Please Select</option>
</select>
</div>
</div>
<div class="row pt-3">
<div class="col-md-2">
<label for="editing">Editing Required</label>
<select class="form-control" name="editing" id="form-editing" onchange="disable('form-editing', 'form-editing-true')">
<option value="no">No</option>
<option value="yes" >Yes</option>
</select>
</div>
<div class="col-md-4">
<label for="editing">Editing Info</label>
<input type="text" placeholder="What Editing" class="form-control" name="editing" id="form-editing-true" disabled value="">
</div>
<div class="col-md-2">
<label for="event">Event</label>
<select class="form-control" name="event" id="form-event" onchange="disable('form-event', 'form-event-true')">
<option value="no">No</option>
<option value="yes" >Yes</option>
</select>
</div>
<div class="col-md-4">
<label for="event">Event Info</label>
<input type="text" placeholder="What Event" class="form-control" name="event" id="form-event-true" disabled value="">
</div>
</div>
<div class="row pt-3">
<div class="col-md-12">
<label for="additional_instructions">Additional Instructions</label>
<textarea class="form-control" name="additional_instructions" id="textEditor" cols="30" rows="10"></textarea>
</div>
</div>
<div class="text-center pt-3">
<button class="btn btn-primary btn-block" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright © eThniks <script>document.write(new Date().getFullYear())</script></span>
</div>
</div>
</footer>
<!-- End of Footer -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
@include('partials.template.logoutmodal')
@endsection
EDIT
@extends('layouts.app')
@section('content')
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
@include('partials.template.sidebar')
<!-- End of Sidebar -->
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Topbar -->
@include('partials.template.navbar')
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><i class="text-warning fas fa-pencil-alt"></i> Forms</h1>
<a href="{{ URL::previous() }}" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-angle-double-left fa-sm text-white-50"></i> Back</a>
</div>
<!-- Content Row -->
<div class="row">
<div class="col-md-12 col-xs-12 col-lg-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Edit the fields below...</h6>
</div>
<div class="card-body">
<form action="" method="">
<div class="row">
<div class="col-md-2">
<label for="job_description">Job No</label>
<input class="form-control" name="job_description" type="text" disabled value="001">
</div>
<div class="col-md-2">
<label for="company">Company</label>
<select class="form-control" name="company" id="company">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="brand">Brand</label>
<select class="form-control" name="brand" id="brand">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-4">
<label for="type_communication">Type of Communication</label>
<select class="form-control" name="type_communication" id="type_communication">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="user_id">User</label>
<input class="form-control" name="user_id" type="text" disabled value="{{Auth::user()->name}}">
</div>
</div>
<div class="row pt-3">
<div class="col-md-4">
<label for="channels">Channels</label>
<select class="js-tags form-control" name="channels[]" multiple="multiple">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="col-md-2">
<label for="frequencies">Frequency</label>
<select class="form-control" name="frequencies" id="frequencies">
<option value="">Please Select</option>
</select>
</div>
<div class="col-md-2">
<label for="">Start Date</label>
<input class="form-control" name="start_date" type="text" data-provide="datepicker">
</div>
<div class="col-md-2">
<label for="">End Date</label>
<input class="form-control" name="end_date" type="text" data-provide="datepicker">
</div>
<div class="col-md-2">
<label for="media_types">Media Types</label>
<select class="form-control" name="media_types" id="media_types">
<option value="">Please Select</option>
</select>
</div>
</div>
<div class="row pt-3">
<div class="col-md-2">
<label for="editing">Editing Required</label>
<select class="form-control" name="editing" id="form-editing" onchange="disable('form-editing', 'form-editing-true')">
<option value="no">No</option>
<option value="yes" >Yes</option>
</select>
</div>
<div class="col-md-4">
<label for="editing">Editing Info</label>
<input type="text" placeholder="What Editing" class="form-control" name="editing" id="form-editing-true" disabled value="">
</div>
<div class="col-md-2">
<label for="event">Event</label>
<select class="form-control" name="event" id="form-event" onchange="disable('form-event', 'form-event-true')">
<option value="no">No</option>
<option value="yes" >Yes</option>
</select>
</div>
<div class="col-md-4">
<label for="event">Event Info</label>
<input type="text" placeholder="What Event" class="form-control" name="event" id="form-event-true" disabled value="">
</div>
</div>
<div class="row pt-3">
<div class="col-md-12">
<label for="additional_instructions">Additional Instructions</label>
<textarea class="form-control" name="additional_instructions" id="textEditor" cols="30" rows="10"></textarea>
</div>
</div>
<div class="text-center pt-3">
<button class="btn btn-primary btn-block" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright © eThniks <script>document.write(new Date().getFullYear())</script></span>
</div>
</div>
</footer>
<!-- End of Footer -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
@include('partials.template.logoutmodal')
@endsection
I tried Clearing the Cache and get the following:
LogicException : Unable to prepare route [api/user] for serialization. Uses Closure.
at C:\wamp64\www\upload\vendor\laravel\framework\src\Illuminate\Routing\Route.php:917
913| */
914| public function prepareForSerialization()
915| {
916| if ($this->action['uses'] instanceof Closure) {
> 917| throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
918| }
919|
920| $this->compileRoute();
921|
Exception trace:
1 Illuminate\Routing\Route::prepareForSerialization()
C:\wamp64\www\upload\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:62
2 Illuminate\Foundation\Console\RouteCacheCommand::handle()
C:\wamp64\www\upload\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32
Please use the argument -v to see more details.
Your routes declaration is all wrong!
It should take the format:
Route::get('/client-form', 'FormController@show');
and the edit will require a variable, that is the item id you wish to edit:
Route::get('/client-form/{id}', 'FormController@edit');
Isn't ::resource suppose to handle that though? That is how one did it in 5.5 and it worked fine, has something changed? Omw lol haha
True enough!
How did you create your controller?
If you used the API option then edit and create are not included:
To quickly generate an API resource controller that does not include the create or edit methods, use the --api switch when executing the make:controller command: php artisan make:controller API/PhotoController --api
https://laravel.com/docs/5.8/controllers#resource-controllers
mmm I used php artisan make:model Form -a
to create all the functions at one time. So, in other words, the show and edit are sort of deprecated in the newer versions of Laravel - kinda sucks makes extra work. I remember it working fine with the same above CLI in 5.7. Eish okay, thank you though for clearing that up! I would have been stuck on this most of the day and not get this done and not have a clue why it wasn't working as usual.
Will keep this in mind. I hate a crowded web.php file. They should bring back that old funcationality that the resource file includes all functions in the route even when created via the above cli or the one you provided from the documentation. :(
THANK YOU :D
No worries, glad to help!!
We've all been there, and probably all will be again :D
Please mark as resolved/best answer.
Please or to participate in this conversation.