jeudi 28 avril 2016

Laravel issue with Carbon throwing an exception

Hi so i'm following the Laracasts But i'm pretty stuck because i'm not sure why i'm getting the error ~: Method Carbon\Carbon::__toString() must not throw an exception

here is my code;

<?php

namespace App\Http\Controllers;


use App\Http\Requests\CreateArticleRequest;
use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Request;
use Carbon\Carbon;

class ArticlesController extends Controller
{
public function index()    {
    $articles= article::all();

   return view ('articles.index',compact ('articles')); 
}

public function show($id){

  $article= article::findOrFail($id);

   return view ('articles.show',compact ('article')); 

}

public function create(){

    return view('articles.create');

}

public function store(Request $request){
    $input = Request::class;
    $input['published_at'] = Carbon::now();

    Article::create($input);

    return redirect('articles');
}

}
}

and here is my front end:

@extends ('app')

@section('content')

<h1> Write a New Article </h1>

<hr/>


{!! Form::open(['url' => 'articles']) !!}
<div class="form-group">
    {!! Form::label('title', 'Title:') !!}
    {!! Form::text('title', null, ['class' => 'form-control']) !!}

</div>
<!-- FORM INPUT HEEEEERREEEE -->
<div class="form-group">
    {!! Form::label('body','Body:') !!}
    {!! Form::textarea('body', null, ['class' => 'form-control']) !!}

</div>

<!-- Add Article field -->
<div class="form-group">
    {!! Form::submit('Add Article',['class' => 'btn btn-primary form-control'] ) !!}

</div>

{!! Form::close() !!}


@stop



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire