bbparis's avatar

Simple communication test with database

Hello all,

You are really very helpful here, so, thank you in advance for your help.

I'm learning by doing some test on the following link : http://demo.beginfromhere.com/laravel/public/users

Based on the following lesson : https://laracasts.com/series/laravel-5-fundamentals/episodes/10?autoplay=true

Why when I send username, notes and email, the result as you will see at the end of the page is empty ?

The PageController file is the following :

<?php

namespace App\Http\Controllers;

use Request;
use App\User;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Carbon\Carbon;

class PagesController extends Controller
{
    public function index()
    {
        $users = User::all();

        return view('pages.index', compact('users'));

    }

    public function users()
    {
        $users = User::all();

        return view('pages.users', compact('users'));

    }
    
       public function show($id)
    {
        $user = User::findOrFail($id);

        return view('pages.show', compact('user'));

    }
    
           public function show2()
    {
      
       return view('pages.show2');

    }

    
        public function store()
    {

        $input = Request::all();
        $input['published_at'] = Carbon::now();
        
        User::create($input);
        
        return redirect ('users');

    }
}
0 likes
5 replies
RomainLanz's avatar

Why when I send username, notes and email, the result as you will see at the end of the page is empty ?

Where do you send these data?

bbparis's avatar

to the same page, I mean Laravel/public/users :

@extends('layouts.master')

@section('title', 'Users Page')

@section('content')
   
   <h1>Add Users</h1>

   {!! Form::open(['url'=>'users']) !!}
       <div class="form-group">
       {!! Form::label('username','User Name:') !!}
       {!! Form::text('username', null, ['class'=>'form-control']) !!}
       </div>
       
       <div class="form-group">
       {!! Form::label('notes','Notes:') !!}
       {!! Form::textarea('notes', null, ['class'=>'form-control']) !!}
       </div>
       
       <div class="form-group">
       {!! Form::label('email','Email:') !!}
       {!! Form::text('email', null, ['class'=>'form-control']) !!}
       </div>
       
       <div class="form-group">
       {!! Form::submit('Submit', ['class'=>'btn btn-primary form-control']) !!}
       </div>
       
   {!! Form::close() !!}
   

    <h1>Users</h1>

    @foreach($users as $user)

         <user>
            <h2>

            {{ $user->id }} ) <a href="{{ url('/users', $user->id) }}">{{ $user->username }}</a>

            </h2>

            <div class="body">User's Notes : {{ $user->notes }}</div>
         </user>


    @endforeach


@endsection
bbparis's avatar

I just resolve the problem by adding (username) and (notes) to my mass assignable inside the class User like the following:

  protected $fillable = ['username','notes', 'email', 'password'];

Now, my question is :

What is the exactly the roll of mass assignable ?

Please or to participate in this conversation.