Support the ongoing development of Laravel.io →
Requests Input Database
Last updated 2 years ago.
0

What you're doing right now isn't setting a property on attendance. You are overriding the attendance model instance completely and replacing it with a string.

I would highly recommend learning the basics of php and object-oriented programming before trying to use Laravel.

0

thomastkim said:

What you're doing right now isn't setting a property on attendance. You are overriding the attendance model instance completely and replacing it with a string.

I would highly recommend learning the basics of php and object-oriented programming before trying to use Laravel.

Thanks, and I thought I was ready for laravel, after spending three years dabbling with php and a bit of OOP. Actually, I came to laravel for the purpose of rapid solutions to daily problems, but, for my surprise I was stuck in a loop where I can't proceed learning laravel and going back to pure php. But, I guess, your opinion is correct, "I'm not ready to laravel, yet.".

0

Oh ok. You might just need some guidance on how to use Laravel. I would recommend Jeffrey Way's series on Laravel. There's a ton of content so it can be overwhelming, but it's great stuff.

This is his series on oop: https://laracasts.com/series/object-oriented-bootcamp-in-php

This is his series on Laravel 5 fundamentals: https://laracasts.com/series/laravel-5-fundamentals

Just note that for the Laravel 5 fundamental series, some things have changed. :) But it will really help you understand the framework conceptually.

0

Thanks a lot @thomastkim for your guidance, and I just want you to guide me to series on php OOP dedicated to learning Laravel.

0

Like @thomastkim said, you are replacing a string to $attendance The return value of Request::input() is either string|array, and therefore you are getting that error .

Reference http://laravel.com/api/5.0/Illuminate/Http/Request.html#method_input

You eventually ended up doing something like this.

 // This does not work as the return type is not Model
$request->input('thursday.' .$key)->save(); 

Just a guess, should $attendance suppose to be an ORM object.

$attendance->tuesday = $request->input('tuesday' . $key); 
0

awsp said:

Like @thomastkim said, you are replacing a string to $attendance The return value of Request::input() is either string|array, and therefore you are getting that error .

Reference http://laravel.com/api/5.0/Illuminate/Http/Request.html#method_input

You eventually ended up doing something like this.

// This does not work as the return type is not Model
$request->input('thursday.' .$key)->save(); 

Just a guess, should $attendance suppose to be an ORM object.

$attendance->tuesday = $request->input('tuesday' . $key); 

Thanks @awsp for your drop by, and I want you to bear with me a bit. I have an edit view for the attendance controller which derived data from Attendance model, like:

{!! Form::model($attendances, ['method' => 'PATCH', 'class' => 'form-horizontal', 'action' =>    ['AttendanceController@update', $course_id]]) !!}
			<table id="myTable" class="table table-striped table-bordered">
				<thead>
					<tr>
						<th>الرقم الأكاديمي</th>
						<th>اسم الطالب</th>
						<th>الأحد</th>
						<th>الاثنين</th>
						<th>الثلاثاء</th>
						<th>الأربعاء</th>
						<th>الخميس</th>
					</tr>
				</thead>
				<tbody>

					@include('partials.errors')
					@include('partials.success')

					
					@foreach ($attendances as $key => $attendance)
						<tr>
							<td>{{ $attendance->student->academic_num }}</td>
							<td>{{ $attendance->student->name }}</td>
							<td>
								{!! Form::text('sunday['.$key.']', $attendance->sunday, null) !!}
							</td>
							<td>
								{!! Form::text('monday['.$key.']', $attendance->monday, null) !!}
							</td>
							<td>
								{!! Form::text('tuesday['.$key.']', $attendance->tuesday, null) !!}
							</td>
							<td>
								{!! Form::text('wednesday['.$key.']', $attendance->wednesday, null) !!}
							</td>
							<td>
								{!! Form::text('thursday['.$key.']', $attendance->thursday, null) !!}
							</td>

						</tr>
					@endforeach
					
				</tbody>

			</table>
				{!! Form::button('  حفظ', ['type' => 'submit','class' => 'fa fa-save btn btn-primary btn-md']) !!}
			{!! Form::close() !!}

But I don't know how to save those data back to database, so , I came up with the stupid way that I posted here at the top of this post.

Could you please help me with a hint?

Last updated 9 years ago.
0

Hooray!!!, I solved my problem, thanks for @thomastkim and @awsp for their hints.

0

this is the solution:

public function update(Request $request, $id)
{
    $attendances = Attendance::where('course_id', '=', $id)->get();
    
    
    foreach ($attendances as $key => $attendance)
    {
        $atts = Attendance::findOrFail($request->input('id.'.$key));

       

        $temp['sunday'] = $request->input('sunday.' .$key);
        $temp['monday'] = $request->input('monday.' .$key);
        $temp['tuesday'] = $request->input('tuesday.' .$key);
        $temp['wednesday'] = $request->input('wednesday.' .$key);
        $temp['thursday'] = $request->input('thursday.' .$key);

        $atts->update($temp);
        
         

    }

    

    return redirect('attendance')->withSuccess('تم ادخال الغياب بنجاح');
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.