Answer the question
In order to leave comments, you need to log in
Does not save data to the database, what's the problem?
I’m making a website on Laravel, I got to the CRUD system and everything seems to be like in the lessons, but the data is not saved in the database when a Post request is made to the store and sends me to the index route (not the site, but the route resource), and does not even return anything what I set in the store.
Route
Route::group(['middleware'=>'auth'],function(){
Route::resource('posts','DashPosts');
});
@extends('site.index')
@section('title','Add new post')
@section('content')
{!! Form::open(['route' => 'posts.store','method'=>'post']) !!}
<h3>{!! Form::label('title', null,['class' => 'label label-default']); !!}</h3>
{!! Form::text('title',null,['class'=>'form-control','placeholder'=>'You title post']); !!}
<h3>{!! Form::label('preview', null,['class' => 'label label-default']); !!}</h3>
{!! Form::text('preview',null,['class'=>'form-control','placeholder'=>'Preview text']); !!}
<h3>{!! Form::label('details', null,['class' => 'label label-default']); !!}</h3>
{!! Form::textarea('details',null,['class'=>'form-control','placeholder'=>'Detail text']); !!}
<div class="row">
<div class="col-md-2">
<h3>{!! Form::label('categoria', 'Categoria',['class' => 'label label-default']); !!}</h3>
{!! Form::select('categoria', $categories,null,['class'=>'form-control']); !!}
</div>
</div>
<h3>{!! Form::label('image', 'Title image',['class' => 'label label-default']); !!}</h3>
{!! Form::text('image',null,['class'=>'form-control','placeholder'=>'Url you image']); !!}
<div style="margin-top:10px;">
<button class="btn btn-success" type="submit">Done</button>
</div>
{!! Form::close() !!}
@endsection
<?php
namespace App\Http\Controllers;
use App\categoria;
use App\all;
use Illuminate\Http\Request;
class DashPosts extends Controller
{
public function index()
{
return view('posts');
}
public function create()
{
$categories = categoria::all();
$categoriesF = array_pluck($categories, 'name');
// print all categories in select tag
return view('addPost', ['categories '=> $categoriesF]);
}
public function store(Request $request)
{
$all = new all;
$all->title = $request->get('title');
$all->preview = $request->get('preview');
$all->details = $request->get('details');
$all->categories = $request->get('categoria');
$all->image = $request->get('image');
// Тут от фонаря данные в лепил к нехватающим данным в бд.
$all->image_url = 'dfdf';
$all->postAuthor = 0;
$all->like = 0;
$all->not_like = 0;
$all->views = 0;
$all->save();
return 'Hello';
}
}
Answer the question
In order to leave comments, you need to log in
The issue is resolved, my stupidity, the conflict of routes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question