I need to submit a form from my blade page to a controller action. It's not working properly as of now. I have the blade view page as follows
index.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<form action="{{route('api.api_submit')}}" method="post">
<div class="form-group"> <label for="country">Country:</label> <input type="text"
class="form-control" name="country" />
</div>
<div class="form-group"> <label for="job_title">Job Title:</label> <input type="text"
class="form-control" name="job_title" />
</div>
<button type="submit" class="btn btn-primary-outline">Submit</button>
</form>
</div>
</div>
@endsection
And Controller as follows :
ApiController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Contact;
class ApiController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('api.index');
}
/**
* 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)
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function api_submit(Request $request)
{
$contacts = Contact::all();
return view('api.show', compact('contacts'));
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* 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)
{
//
}
}
And in routes/web.php I have
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
/**
* API routes
*/
Route::get('/api', function () {
return view('api/index');
});
Route::get('/api/v1', 'ApiController@index');
Route::post('/api/api_submit', 'ApiController@api_submit');
But whenever I call http://localhost:8000/api it throws me error as
Route [api.api_submit] not defined
. Why is it like that? Is there anything to do more to get that particular route to work?
I also tried to give resource route Route::resource('api', 'ApiController');. It also didn't work.
Attaching the screenshot below.

You must name your route.