Problem is how you fetch data.
$meetings = DB::table('apac_meetings')->get();
In this case you doesn't use Eloquent. Change it to:
$meetings = Meeting::all();
and that should work.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey all, I'm attempting to pull some date values from my database, and format them as they're displayed. My database has a field "deadline" of datatype "DATE", which has a value that's for example, "2017-01-13", or Y-M-D format. I try to echo out my data with:
{{$meeting->deadline->format('m-d-Y')}}
and I get the error: "Call to a member function format() on string"
Anyone know the correct way to format this? My model looks like:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Meeting extends Model
{
protected $table = 'apac_meetings';
protected $dates = ['deadline', 'meeting_date'];
protected $fillable = ['deadline' , 'meeting_date', 'meeting_start', 'meeting_end', 'meeting_location'];
}
My route:
Route::resource('/meetings', 'MeetingsController');
and my Controller:
<?php
namespace App\Http\Controllers;
use DB;
use Illuminate\Http\Request;
use \App\Http\Controllers\Controller;
use \App\Meeting;
class MeetingsController extends Controller
{
public function index(){
$meetings = DB::table('apac_meetings')->get();
return view('meetings', ['meetings' => $meetings]);
}
public function update(Request $request, Meeting $meeting)
{
//Validate
$request->validate([
'deadline' => 'required',
'meeting_date' => 'required',
'meeting_start' => 'required',
'meeting_end' => 'required',
'meeting_location' => 'required',
]);
$meeting->deadline = $request->deadline;
$meeting->meeting_date = $request->meeting_date;
$meeting->meeting_start = $request->meeting_start;
$meeting->meeting_end = $request->meeting_end;
$meeting->meeting_location = $request->meeting_location;
$meeting->save();
$request->session()->flash('message', 'Successfully modified the task!');
return redirect('meetings');
}
}
Yes if they are the column names. However you also need to list created_at and updated_at if you have those in your table
However @Cinek has the right answer, casting to Carbon is only performed in eloquent models
Please or to participate in this conversation.