Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mhmmdva's avatar

'dates' cannot display in edit views

migration file

class CreateLogbooksTable extends Migration
{    
    public function up()
    {
        Schema::create('logbooks', function (Blueprint $table) {
            $table->id();
            // relational
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('proposal_id')->constrained('proposals')->cascadeOnDelete();

            // detail
            $table->date('date'); 
            $table->text('activity');
            $table->integer('percentage');
            $table->text('file')->nullable();
            
            $table->timestamps();
        });
    }
}

model

class Logbook extends Model
{
    use HasFactory;

    protected $guarded = ['id'];
    protected $dates = ['date']; // problem in here
    const LOGBOOK_PATH = 'public/data/logbooks';
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function proposal()
    {
        return $this->belongsTo(User::class);
    }

}

edit.blade.php

<input type="date" name="date" value="{{ old('date') ??  $logbook->date }}">
0 likes
6 replies
aisuvro's avatar

If you try to show the other variables like 'activity', is it visible in the input text?

1 like
mhmmdva's avatar

@Tray2


class LogbookController extends Controller
{
 
    public function index(Proposal $proposal)
    {
        return view('admin.lecturers.proposals.logbooks.index', [
            'proposal' => $proposal,
            'logbooks' => $proposal->logbook,
        ]);
    }

    public function create(Proposal $proposal)
    {
        return view('admin.lecturers.proposals.logbooks.create', [
            'proposal' => $proposal
        ]);
    }

    public function store(LogbookRequest $request, Proposal $proposal)
    {
        $data = $request->validated();

        if ($request->hasFile('file')) {
            $file = $request->file('file');
            $uploadFileName = Str::of($file->getClientOriginalName())->replace(' ', '-');
            $fileName = pathinfo($uploadFileName, PATHINFO_FILENAME);
            $fileExtension = $file->getClientOriginalExtension();
            $name = $fileName . '-' . now()->format('dmyhis') . '.' . $fileExtension;
            $fileUrl = $file->storeAs(Logbook::LOGBOOK_PATH, $name); // given the name with storeAs()
            $data['file'] = $fileUrl;
        }

        $data['user_id'] = auth()->user()->id;
        $data['proposal_id'] = $proposal->id;
        
        Logbook::create($data);

        return redirect()->route('lpp.proposal.logbook.index', $proposal->slug)->with('success', 'success');
    }

    public function edit(Proposal $proposal, Logbook $logbook)
    {
        return view('admin.lecturers.proposals.logbooks.edit', [
            'proposal' => $proposal,
            'logbook' => $logbook,
        ]);
    }

 public function update(LogbookRequest $request, Proposal $proposal, Logbook $logbook)
    {
        $data = $request->validated();

        if ($request->hasFile('file')) {
            if ($logbook->file != null) {
                Storage::delete($logbook->file);
            }
            $file = $request->file('file');
            $uploadFileName = Str::of($file->getClientOriginalName())->replace(' ', '-');
            $fileName = pathinfo($uploadFileName, PATHINFO_FILENAME);
            $fileExtension = $file->getClientOriginalExtension();
            $name = $fileName . '-' . now()->format('dmyhis') . '.' . $fileExtension;
            $fileUrl = $file->storeAs(Logbook::LOGBOOK_PATH, $name);
            $data['file'] = $fileUrl;
        }        

        $logbook->update($data);

        return redirect()->route('lpp.proposal.logbook.index', $proposal->slug)->with('success', 'success');
    }


}

1 like
tisuchi's avatar
tisuchi
Best Answer
Level 70

@mhmmdva Try this:

<input type="date" name="date" value="{{ old('date') ??  $logbook->date->format('Y-m-d') }}">
1 like
mhmmdva's avatar

@tisuchi thank you, the problem has been solved. I thought that I couldn't format the value

2 likes

Please or to participate in this conversation.