Hy, I'm trying to post an action from a form directly to the controller store method (It's a create action). I use laravel 5.5 and decided to use pure HTML. But after clicking the submit button, nothing goes into the database. How can I fix this....
see the route for that controller method
Route::resource('admin/properties', 'AdminPropertiesController', ['as' => 'admin']);
see the controller store method itself
namespace App\Http\Controllers;
use App\Http\Requests\PropertiesCreateRequest;
use Illuminate\Http\Request;
use App\Property;
use App\Category;
use App\Photo;
class AdminPropertiesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$properties = Property::all();
return view('admin.properties.index', compact('properties'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
$categories = Category::all();
return view('admin.properties.create', compact('categories'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(PropertiesCreateRequest $request)
{
//
//get all available inputs
$input = $request->all();
//get the logged in user
$user = Auth::user();
//grab the photo_id from users table
if($file = $request->file('photo_id')){
//concatenate time ti filename
$name = time() . $file->getClientOriginalName();
//move named file to images folder, that wil b automatically created
$file->move('images', $name);
//main photo table column(key) having a value of filename frm users table
$photo = Photo::create(['cover_image'=>$name]);
//equatin the user photo_id to the photo->id frm the main photos table
$input['photo_id'] = $photo->id;
}
/* $Category = Category::create($input); */
//to mk sure only logged in user Categorys are created.
//tis is why we av the hasMany r/s in Users Model, so that whn a logged-in user cn create morethan one Category
$user->properties()->create($input);
return redirect('/admin/properties');
}
/**
* 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)
{
//
}
}
see the create view
@section('content')
{{-- Display errors where neccessary --}}
@include('inc.message')
<h1>Create Properties</h1>
{{-- <form action="{{ action('AdminPropertiesController@store') }}" method="POST" enctype="multipart/form-data"> --}}
{{-- <form action="/admin/properties" method="POST" enctype="multipart/form-data"> --}}
<form action="{{ route('admin.properties.store') }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="title">Title:</label>
<input type="title" class="form-control" id="title">
</div>
<div class="form-group">
<label for="photo_id">Photo:</label>
<input type="file" class="form-control" id="photo_id">
</div>
<div class="form-group">
<label for="price">Price:</label>
<input type="price" class="form-control" id="price">
</div>
<div class="form-group">
<label for="location">Location:</label>
<input type="location" class="form-control" id="location">
</div>
<div class="form-group">
<label for="description">Description:</label>
<input type="description" class="form-control" id="description">
</div>
<div class="form-group">
<label for="bedroom">Bedroom:</label>
<input type="bedroom" class="form-control" id="bedroom">
</div>
<div class="form-group">
<label for="bathroom">Bedroom:</label>
<input type="bathroom" class="form-control" id="bathroom">
</div>
@if(count($categories) > 0)
<div class="form-group">
<label for="category_id">Category:</label>
<select class="form-control" id="category_id" name="category_id">
<option>Choose Options</option>
@foreach($categories as $category)
<option value="{{$category->id}}" name="cat_ref_id">{{ $category->demand }}</option>
@endforeach
</select>
</div>
@endif
<input type="submit" class="btn btn-default" name="submit">
{{-- <button type="submit" class="btn btn-default">Submit</button> --}}
</form>
@endsection ```
Thanks alot