0
votes

I've made a few posts about laravel but this is definitely the most stuck I've been. I'm making a blog app for myself to learn Laravel, it was working amazingly smooth until I change the file structure from:

-[views]
--[blogs]
---index.blade.php
---create.blade.php
---show.blade.php

To:

-[views]
--index.blade.php
--create.blade.php
--[admin]
---show.blade.php

This is my routes file:

Route::get('/', 'Blogs@index')->name('blogs_path');
Route::get('/admin/create', 'Blogs@create')->name('create_blogs_path');
Route::get('/', 'Blogs@store')->name('store_blogs_path');
Route::get('/{id}', 'Blogs@show')->name('blog_path');

Here's my blog controller file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Blog;

class Blogs extends Controller
{
    //

    public function index(){

        $blogs = Blog::all();

        return view('index', ['blogs' => $blogs]);
    }

    public function show($id){

        $blog = Blog::find($id);

        return view('show', ['blog' => $blog]);
    }

    public function create(){

        return view('admin.create');
    }

    public function store(Request $request){

        $blog = new Blog;

        $blog->title = $request->title;
        $blog->content = $request->content;
        $blog->created_at = $request->created_at;

        $blog->save();

        return redirect()->route('blogs_path');
    }
}

It was working completely fine in the old file structure, but as soon as I take it one level back it all broke. Here's the error I'm getting:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null (SQL: insert into 'blogs' ('title', 'content', 'created_at', 'updated_at') values (?, ?, ?, 2020-04-23 20:10:20))

Yet I have data in the table and it worked perfectly fine before.

Thanks.

1
Are you tried php artisan optimize:clearMortada Jafar
just done that, didn't work.tzcoding
please show me dd($request->all()) resultMortada Jafar
I can't put that anywhere because my files wont load because of errors.tzcoding
This route Route::get('/', 'Blogs@store')... should have post method, not get Route::post('/', 'Blogs@store')...porloscerros Ψ

1 Answers

0
votes

The / route is repeated twice:

Route::get('/', 'Blogs@index')->name('blogs_path');
...
Route::get('/', 'Blogs@store')->name('store_blogs_path');
...

Fixing that should work.