Я новичок в laravel, и я работаю в операции CRUD контроллера ресурсов. Я сделал с функцией show, и мой интерфейс получит идентификатор от пользователя, и мне нужно показать детали, используя идентификатор. Для этого я использовал функцию показа контроллера ресурса. Проблема в том, как вернуть идентификатор? я пробовал с нижеуказанными форматами
http://localhost/sbadmin/public/invoice/invoice/show?12 http://localhost/sbadmin/public/invoice/invoice/show/12
оба возвращают только 404.
Может кто-нибудь предложить Как написать этот URI?
Вот мой веб. php
<?php
Route::prefix('invoice')->group(function() {
Route::get('/createInvoice', 'Invoice\InvoiceController@getAllInvoiceDetails');
Route::post('/addInvoice', 'Invoice\InvoiceController@addInvoice');
Route::post('/checkPhoneNumberAndFetchData', 'Invoice\InvoiceController@checkPhoneNumberAndReturnData');
Route::resource('invoice', 'Invoice\InvoiceManagementController')->only([
'index', 'show'
]);
Route::get('/searchInvoice','Invoice\InvoiceController@searchInvoice');
Route::get('/viewAllInvoice','Invoice\InvoiceController@viewAllInvoice');
Route::get('/viewInvoicesAsJson','Invoice\InvoiceController@viewInvoicesAsJson');
});
Контроллер:
namespace Modules\Invoice\Http\Controllers\Invoice;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Modules\Invoice\Entities\Invoice;
class InvoiceManagementController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('invoice::viewinvoices');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//return $id;
$invoices = Invoice::findOrFail($id)->with(['user','events','payments'])->get();
return view('invoice::invoice');
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
/**
* Responds to requests to GET /users/show/1
*/
public function getShow($id)
{
//
}
}
blade. php:
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
<div class="col-lg-7">
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Search Invoice</h1>
</div>
<form id="form" onsubmit="return OnSubmitForm();" >
@csrf
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="text" class="form-control form-control-user" name="invoice_id" id="id" placeholder="Enter Invoice number" >
</div>
</div>
<button type="submit" class="btn btn-primary btn-user btn-block">
View Invoice
</button>
<hr>
<a href="index.html" class="btn btn-google btn-user btn-block" hidden="">
<i class="fab fa-google fa-fw"></i> Register with Google
</a>
<a href="index.html" class="btn btn-facebook btn-user btn-block" hidden="">
<i class="fab fa-facebook-f fa-fw"></i> Register with Facebook
</a>
</form>
<div class="text-center" hidden="">
<a class="small" href="forgot-password.html">Forgot Password?</a>
</div>
<div class="text-center" hidden="">
<a class="small" href="login.html">Already have an account? Login!</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="{{ asset('sbadmin/vendor/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('sbadmin/vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<!-- Core plugin JavaScript-->
<script src="{{ asset('sbadmin/vendor/jquery-easing/jquery.easing.min.js') }}"></script>
<!-- Custom scripts for all pages-->
<script src="{{ asset('sbadmin/js/sb-admin-2.min.js') }}"></script>
<script type="text/javascript">
function OnSubmitForm()
{
$('#form').prop('action',"invoice/show/"+$('#id').val());
return true;
}
</script>