Я очень новичок в Laravel, сейчас я использую версию 5.7.и так как я пытаюсь поместить некоторые данные формы в таблицу MySQL, я получаю эту ошибку.
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Нет сообщения
Однако я понятия не имею, что япошло не так.пожалуйста, помогите мне, если можете.Пожалуйста, смотрите мой код ниже.
Мои маршруты:
Route::get('/invo_admin/create_new_offer', 'CreatenewofferController@index')->name('create_new_offer');
Также у меня есть подпапка с именем admin, где у меня есть свои представления для панели инструментов.
Route::resource('admin', 'CreatenewofferController');
Моя модель:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Offers extends Model
{
protected $fillable =[
'offer_name',
'offer_image',
'offer_discription',
'offer_vendor',
'offer_reward_amount',
'offer_limit',
'offer_duration',
'offer_status'
];
}
Мой контроллер:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Offers;
class CreatenewofferController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$title = 'this is a title';
return view('admin.create_new_offer')->with('title',$title);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.create_new_offer');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,[
'offer_name' => 'required',
'offer_image' => 'required',
'offer_discription' => 'required',
'offer_vendor' => 'required',
'offer_reward_amount' => 'required',
'offer_limit' => 'required',
'offer_duration' => 'required',
'offer_status' => 'required'
]);
$offers = new Offers([
'offer_name' => $request->get('offer_name'),
'offer_image' => $request->get('offer_image'),
'offer_discription' => $request->get('offer_discription'),
'offer_vendor' => $request->get('offer_vendor'),
'offer_reward_amount' => $request->get('offer_reward_amount'),
'offer_limit' => $request->get('offer_limit'),
'offer_duration' => $request->get('offer_duration'),
'offer_status' => $request->get('offer_status')
]);
$offers->save();
return redirect()->route('admin.create_new_offer')->with('success', 'You have successfully added a new offer');
}
}
Мой вид:
<form role="form" method="POST" action="{{ url('invo_admin/create_new_offer') }}">
{{csrf_field()}}
<!-- text input -->
<div class="form-group">
@if(count($errors) > 0)
<ul>
@foreach ($errors ->all as $error)
<li class="text-danger">{{error}}</li>
@endforeach
</ul>
@endif
@if(\Session::has('success'))
<p>{{\Session::get('success')}}</p>
@endif
<label>Name</label>
<input type="text" class="form-control" name="offer_name" placeholder="Offer Name">
</div>
</form>