Getting 404 Not found though route exists, the following codes worked perfectly on Laravel 8 but on 6 produces 404.
Route:
// Content Packs
Route::delete('content-packs/destroy', 'ContentPacksController#massDestroy')->name('content-packs.massDestroy');
Route::patch('content-packs/{content-pack}/clone_pack', 'ContentPacksController#clone_pack')->name('content-packs.clone_pack');
Route::resource('content-packs', 'ContentPacksController');
Button:
<form action="{{ route('admin.content-packs.clone_pack', $contentPack->id) }}" method="POST" onsubmit="return confirm('{{ trans('cruds.contentPack.clone_confirmation') }}');" style="display: inline-block;">
<input type="hidden" name="_method" value="PATCH">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="btn btn-xs btn-warning" value="{{ trans('cruds.contentPack.clone') }}">
</form>
Controller method:
public function clone_pack(Request $request, ContentPack $contentPack)
{
$contentPack = ContentPack::where('id', $request->id)->first();
$newPack = $contentPack->replicate();
$newPack->created_at = Carbon::now();
$newPack->save();
return back();
}
What am I missing?
Changing route to this fixed the issue:
Route::get('content-packs/content-pack/{id}', 'ContentPacksController#clone_pack')->name('content-packs.clone_pack');
Related
I have done everything the right way but my submit button doesnt do anything and I dont know why....
Here is my view
<form action="{{ route('importUser') }}" method="POST" enctype="multipart/form-data">
#csrf
add users via excell<input name="file" class="form-control" style="padding-bottom:3em; margin-bottom:3em" type="file">
<div style="display:inline;">
<input type="submit" class="btn btn-primary btn-lg" value="ارفع" >
</div>
</form>
Here is my controller
function importUser(Request $request)
{
#code...
}
and my route
Route::POST('ImportUsersFile', 'ExcelUserController#importUser')->name('importUser')->middleware('Admin');
Apparently, the flow dont get in the function import user. I tried to dd into it but nothing happend!
According to an error message you provided in a comment, try this:
php artisan key:generate
Try using url intead of route
<form action="{{ url('ImportUsersFile') }}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
add users via excell<input name="file" class="form-control" style="padding-bottom:3em; margin-bottom:3em" type="file">
<div style="display:inline;">
<input type="submit" class="btn btn-primary btn-lg" value="ارفع" >
</div>
</form>
And in your routes:
Route::post('ImportUsersFile', ['uses' => 'ExcelUserController#importUser', 'as' => 'importUser']);
I am trying to add new user using Mikrotik PHP API in Laravel. I can use the API for other usage (like view user information) but when I try to create new user, it gives me nothing, even no error, just redirect me to intended page.
My route is
Route::post('/isp/addUser', 'MainController#addUser');
My Form request is
<form method="POST" action="{{ action('MainController#addUser') }}">
{{ csrf_field() }}
#foreach ($networks as $network)
<input type="hidden" name="user_name" value="{{ $user->name }}">
<input type="hidden" name="ip" value="{{ $network->ip }}">
<input type="hidden" name="user" value="{{ $network->m_username }}">
<input type="hidden" name="pass" value="{{ $network->m_password }}">
#endforeach
<button type="submit" class="btn btn-primary btn-sm text-uppercase">
<strong>add</strong>
</button>
</form>
My Controller method is
public function addUser(Request $request) {
$API = new routeros_api();
$API->user_name = $request->user_name;
$API->ip = $request->ip;
$API->user = $request->user;
$API->pass = $request->pass;
if ($API->connect($request->ip, $request->user, $request->pass)){
$API->comm("/ppp/secret/add/name={{ $API->user }}/password=123456/service=ppoe/profile=1-MBPS");
$API->disconnect();
}
return redirect('/isp');
}
This is not even giving any error, so I am not getting any clue. I think I am not sending the request properly, but got no clue how to do it.
for creating user you should send
$API->comm('/user/add',['name'=>$username,'password'=>$password,'group'=>'read']);
for more information you can check https://mikrotik.com/documentation/manual_2.4/System/Users.html
hope this helps
I am trying to delete item from a generated table of items which are from a database table.
My Route:
Route::delete('destroy/{deviceID}', ['as' => 'destroyDevice', 'uses' => 'DeviceController#destroyDevice']);
My Controller method to delete an item:
public function destroyDevice(Request $request, $deviceId = 0)
{
$device = Device::find($deviceId);
if($device)
{
$device->delete();
return redirect()->route('index')->with('success', 'Erfolgreich gelöscht');
}
else
{
return redirect()->route('index')->with('error', 'Fehler');
}
}
And my blade template:
<form action="{{ route('destroyDevice', $deviceValue->id) }}" method="post" name="delete_device">
<input type="hidden" name="_method" value="delete">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="id" value="{{ $deviceValue->id }}">
<td>
<button type="submit" class="btn btn-danger" name="destroy_device">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</form>
If I click on the button nothing happens no error no Response, what am I doing wrong.
If I click on the third delete button the form holds this:
<form action="http://localhost/app/public/device/destroy/3" method="post" name="delete_device"></form>
You can solve this by putting the form inside a td tag in that table.
Like this:
<td> <!-- <--- put these -->
<form action="{{ route('destroyDevice', $deviceValue->id) }}" method="post" name="delete_device">
<input type="hidden" name="_method" value="delete">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="id" value="{{ $deviceValue->id }}">
<button type="submit" class="btn btn-danger" name="destroy_device">
<span class="glyphicon glyphicon-trash"></span>
</button>
</form>
</td> <!-- <--- put these -->
I think the form gets ignored somehow due to not being valid, but I am not 100% sure. May people edit this answer ;)
The parameter is case sensitive so it should be deviceID instead of deviceId
public function destroyDevice(Request $request, $deviceID = 0)
Maybe you have some script that prevents the form to submit, some prevent default maybe on button click or on form submit. Check that.
I can't seem to find out why does my submit give me back the MethodNotAllowedException. Shortened...here is the form:
<form role="form" id="tryitForm" class="form-horizontal" enctype="multipart/form-data"
method="POST" action="{{route('user.update', Auth::user()->id)}}">
<input type="submit" class="btn btn-primary" name="save" value="Update"/>
And I have route set up as:
Route::resource('user', 'UserController');
You need to add PUT method into your form.
<input name="_method" value="PUT" type="hidden">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
I have a simple form for updating book info.
<form action="{{ action('BookController#update') }}" method="POST" class="form-horizontal">
<input type="text" id="title" class="form-control" name="title" placeholder="title" value="{{ $book[0]->title }}">
<input type="text" id="author" class="form-control" name="author" placeholder="author" value="{{ $book[0]->author }}">
......................
<button type="submit" class="btn btn-primary">Save</button>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
</form>
Controller:
public function update(Request $request, $id)
{
$book = new Book;
$title = $request->input('title');
$author = $request->input('author');
$category = $request->input('category');
$date = $request->input('date');
if ($book->updateBook($id, $title, $author, $category, $date)) {
return redirect('books')->with('status', 'Successfuly edited!');
}
else {
return dd($id);
}
}
The problem is, it doesn't pass the right $id. It pass a string {books}
Basically $id = "{books}"
It should be an integer (31) from url /books/31/edit
In routes is defined as a resource with all available default methods
What can i do?
You need to pass the book's ID in the form definition, as the second argument to action():
<form action="{{ action('BookController#update', ['id' => $book[0]->id]) }}" method="POST" class="form-horizontal">
See the definition of action() for more information.
The solution was very simple: i just needed to pass $id to the view and then pass it to form action as #EricMakesStuff suggested..
try this
<form action="{{ action('BookController#update', ['id'=> 1]) }}" method="POST" class="form-horizontal">