I am new to Laravel and I am trying to figure out how I can submit data from one view to another. I've tried to read some other similar questions on here and watch some videos on this, but I am still not able to get it. Basically I have 3 submit buttons, and the data that's being passed over is from a form. I set up a new route and a function in my controller, but I am getting the error: Declaration of App\\Http\\Controllers\\PagesController::CallAction() should be compatible with Illuminate\\Routing\\Controller::callAction($method, $parameters)
. However I think I am following the correct format.
Here is my web.php:
Route::group(['middleware' => ['auth']], function() {
// CallCenter page
public function CallCenter() {
return view('Pages.CallCenter');
}
Route::post(
'/CallAction/', 'PagesController@CallAction'
);
});
Auth::routes();
My PagesController:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PagesController extends Controller
{
// CallCenter page
public function CallCenter() {
return view('Pages.CallCenter');
}
// CallAction page
public function CallAction() {
return view('Pages.CallAction');
}
}
And the from:
<form action="/CallAction" method="post">
@csrf
<table style="width:70%">
<tr>
<td width="33%">Date<BR>
<?php
date_default_timezone_set('America/Chicago');
echo date('m/d/y');
?>
</td>
<td width="33%">Time<BR>
<?php
date_default_timezone_set('America/Chicago');
echo date('h:i');
?>
</td>
<td width="33%">Campus<BR>
<select name="campus">
<option disabled selected value>-- Campus --</option>
<option value="XXX1"></option>
<option value="XXX2"></option>
<option value="XXX3"></option>
<option value="XXX4"></option>
<option value="XXX5"></option>
</select>
</td>
</tr>
<tr>
<td width="33%">Extension<BR>
<input name="extension" type="text" size="15">
</td>
<td width="33%">Name<BR>
<input name="customerName" type="text" size="40">
</td>
<td width="33%">Email<BR>
<input name="customerEmail" type="text" size="50">
</td>
</tr>
<tr>
<td colspan="3">Description<BR>
<textarea name="description" rows="2" cols="125"></textarea>
</td>
</tr>
<tr>
<td width="33%"><input type="submit" name="convert" value="Convert to Ticket"></td>
<td width="33%"><input type="submit" name="close" value="Close Issue"></td>
<td width="33%"><input type="submit" name="hold" value="Put Issue on Hold"></td>
</table>
</form>
Issue:
The issue is that your Controller is extending App\\Http\\Controllers\\Controller
which in turn extends the abstract class Illuminate\\Routing\\Controller as BaseController
. This BaseController
already has a method called callAction()
defined like this:
public function callAction($method, $parameters)
{
return call_user_func_array([$this, $method], $parameters);
}
So if you want to have a method called callAction()
in your controller, you need to provide the same interface and accept a $method
and a $parameters
array.
Solution:
The quick solution would be to rename your controller method CallAction()
to something that does not conflict with a method name on the parent classes ... maybe CallMyAction()
then update your route file to match the new name.
So you're doing everything right, you just picked a method name that was already defined elsewhere in the framework.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.