meglo

meglo

Member Since 2 Weeks Ago

Experience Points
1,040
Total
Experience

3,960 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
1,040 XP
Oct
26
2 days ago
Activity icon

Replied to Dettach Controller Helpp..

i already change it

    Route::get('/attendance/{attendance}/show', '[email protected]');
    Route::post('/attendance/{attendance}/adddate', '[email protected]');
    Route::delete('/attendance/{attendance}/show/{worker}', '[email protected]');

form delete

<form action="/attendance/{{$attendance->id}}/show/{{$worker->id}}" method="post" class="d-inline">
@method('delete')
@csrf
<button class="btn btn-warning btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i></button>
</form>

controller

    public function deleteattendance(Worker $worker, Attendance $attendance)
    {
        $attendance->worker()->detach($worker['id']);
        return redirect('attendance'.$attendance.'show');
    }
Activity icon

Replied to Dettach Controller Helpp..

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The DELETE method is not supported for this route. Supported methods: GET, HEAD. http://127.0.0.1:8000/attendance/1/show/

sir it still error sir please help me sir

Activity icon

Replied to Dettach Controller Helpp..

sir i dont understand, i really newbe about laravel.

i will show all my data

my detail.blade.php

<table class="table table-hover table-in-card">
                        <thead>
                            <tr>
                                <th scope="col">No</th>
                                <th scope="col">Name</th>
                                <th scope="col">Info</th>
                                <th scope="col" class="">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i=1;?>
                            @foreach ($attendance->worker as $k)
                            <tr>
                                <th scope="row">{{ $i }}</th>
                                <td>{{$k->name}}</td>
                                <td>{{$k->pivot->info}}</td>
                                <td>
  <form action="/attendance/{{$attendance->id}}/workers/{{$worker->id}}" method="post" class="d-inline">
@method('DELETE')
@csrf
 <button class="btn btn-warning btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i></button>
                                    </form>
                                </td>
                            </tr>
                            <?php $i++;?>
                            @endforeach
                        </tbody>
                    </table>

my route

Route::get('/attendance/detail/{id}', '[email protected]');
Route::post('/attendance/adddate/{id}', '[email protected]');
Route::delete('/attendance/{attendance}/workers/{worker}', '[email protected]');

my controller

    public function deleteattendance(Worker $worker, Attendance $attendance)
    {
        $attendance->worker()->detach($worker['id']);
        return redirect('attendance/detail/'.$id);
    }

my model

//Attendance.php
class Attendance extends Model
{
    protected $table = 'attendance';
    protected $fillable = ['date'];

    public function worker() {
        return $this->belongsToMany(Worker::class)->withPivot(['info'])->withTimeStamps();
    }
}

//worker.php

class Worker extends Model
{
    protected $table = 'worker';

    protected $fillable = ['name','Date_birth', 'gender','address', 'phone',  'join_date', 'end_date', 'status'];

    public function attendance() {
        return $this->belongsToMany(Attendance::class)->withPivot(['info'])->withTimestamps();
    }
}

//Attendance_worker.php

class Attendance_worker extends Model
{
    protected $table = 'attendance_worker';

    protected $fillable = ['info'];
}

i appreciate you sir, really thank full, to want respon me about my case i already 2 weeks think about this..

Activity icon

Replied to Dettach Controller Helpp..

yah i know if i want delete worker_id 3 with ->detach(3),

i mean like this i can delete in button delete, not with that way just put 3 value in controller..

if that button work i can delete single row 1 by 1, thats i mean sir.

Activity icon

Replied to Dettach Controller Helpp..

yah i know, i mean if i using delete button i can delete 1 by 1, not only 3. i confusing to make that logic on my controller. please help me to make example.

Activity icon

Replied to Dettach Controller Helpp..

i want detach that single row for worker_id 3 with attendance_id 1

i have 3 table.

table worker

table attendance

table attendance_worker
Activity icon

Started a new Conversation Dettach Controller Helpp..

how to delete from this pivot table

id | worker_id | attendance_id |    info
1          2             1               present
2          3             1               present
3          2             2               present
4          3             2               absent

i want delete that single row for worker_id 3 with attendance_id 1

i try with my controller

    public function deleteattendance($id)
    {
        $worker_id = Attendance_worker::all();
        $data= Attendance::find($id);
        $data->Worker()->detach($worker_id);
        return redirect('attendance/detail/'.$id);
    }

Activity icon

Replied to About Delete Function , And Make A Logic

oh sorry if that's not allowed, im sorry i dont know. i dont get answer. sorry I am so frustrated with this case

Activity icon

Replied to About Delete Function , And Make A Logic

i missing the quotation mark like @zuruck said. but the new problem is now when i hit delete button. image

no error but the data not delete in table attendance_worker. if i back to that attendance date.

image

Oct
25
3 days ago
Activity icon

Replied to About Delete Function , And Make A Logic

maybe because in the attendance / detail / id view, I call model Attendance :: class, but in the controller section deleteattendance I call model Attendance_worker :: class

So if the fault is caused by this, what should it be like?

Activity icon

Replied to About Delete Function , And Make A Logic

<?php $i=1;?>
       @foreach ($attendance->worker as $k)
           <tr>
                <th scope="row">{{ $i }}</th>
                <td>{{$k->name}}</td>
                <td>{{$k->pivot->info}}</td>
                <td>
   <form action="/attendance/delete/presence/{{$attendance->id}}" method="post" class="d-inline>
          @method('delete')
          @csrf
<button class="btn btn-warning btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i></button>
           </form>
             </td>
             </tr>
            <?php $i++;?>

i already change it, it still error,..

Activity icon

Started a new Conversation About Delete Function , And Make A Logic

excuseme, i have case like this.. i get error when i click delete button

i have 3 table 1. worker_table 2. attendance_table 3. attendance_worker_table

detail for migration.

Schema::create('worker', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name',30);
            $table->date('Date_birth');
            $table->string('gender',10);
            $table->text('address');
            $table->char('phone',13);
            $table->date('join_date');
            $table->date('end_date')->nullable();;
            $table->string('status', 10);
            $table->timestamps();
        });
Schema::create('attendance', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date');
            $table->timestamps();
        });
        if (Schema::hasTable('attendance')) {
            Schema::table('attendance_worker', function (Blueprint $table) {
                $table->foreign('attendance_id')
                    ->references('id')->on('attendance');
            });
        }
Schema::create('attendance_worker', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->foreignId('worker_id');
            $table->foreignId('attendance_id');
            $table->string('info',100);
            $table->timestamps();
        });

        Schema::table('attendance_worker', function (Blueprint $table) {
            $table->foreign('worker_id')
                ->references('id')->on('worker')
                ->onDelete('cascade');
        });

and this is my AttendancesController

public function deleteattendance(Attendance $id)
    {
        $data= Attendance_worker::where('worker_id');
        //dd($data);
        $data->forceDelete();
        return redirect('attendance/detail/'.$id);
    }

myroute

Route::get('/attendance/detail/{id}', '[email protected]');
Route::post('/attendance/adddate/{id}', '[email protected]');
Route::delete('/attendance/delete/presence/{id}', '[email protected]');

my detail.blade.php i use modal for pop up to insert attendance form

<table class="table table-hover table-in-card">
                        <thead>
                            <tr>
                                <th scope="col">No</th>
                                <th scope="col">Name</th>
                                <th scope="col">Info</th>
                                <th scope="col" class="">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i=1;?>
                            @foreach ($attendance->worker as $k)
                            <tr>
                                <th scope="row">{{ $i }}</th>
                                <td>{{$k->name}}</td>
                                <td>{{$k->pivot->info}}</td>
                                <td>
                                    <a href="/attendance/delete/presence/{{$k->id}}">
                                        <button class="btn btn-warning btn btn-danger btn-sm">DELETE</button>
                                    </a>
                                </td>
                            </tr>
                            <?php $i++;?>
                            @endforeach
                        </tbody>
                    </table>

screen shoot form detail.blade.php image

and if i click the "add attendance worker", it will make pop up modal like this image

and this is my error if i click delete button image

Oct
24
4 days ago
Activity icon

Replied to SPATIE, Role And Permmision

sorry i already solve it

Activity icon

Started a new Conversation SPATIE, Role And Permmision

i have error like this

Return value of App\User::getStoredRole() must implement interface Spatie\Permission\Contracts\Role, null returned

if i doing edit data, here my controller

public function edit(Request $request, $id)
    {
        $user = User::find($id);
        $roles = Role::all();
        $permissions = Permission::all();
        $roles_name = $user->getRoleNames();
        $permission_name = $user->permissions;
        // dd($permission_name);

        if ($request -> isMethod('post')) {
            $data = $request->all();
            // dd($data);
            $role = Role::findById($data['role']);

            if ($roles_name == true) {
                $user->removeRole($roles_name[0]);
                $user->revokePermissionTo($$permission_name);
            }

            if (count($data['permission'] > 0)) {
                foreach ($data['permission'] as $key => $value){
                    $user->givePermissionTo($data['permission'][$key]);
                    $user->assignRole($role);
                    $role->givePermissionTo($data['permission'][$key]);
                }
            }
            return redirect()-> route('setting')->with('status', 'User berhasil di update');
        }
        return view ('setting.edit_setting', compact('user', 'roles', 'permissions'));
    }
Oct
22
6 days ago
Activity icon

Replied to Always Error When Migrating Table

im sorry wrong copy error

here this one

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table model_has_permissions add index model_has_permissions_model_id_model_type_index(model_id, model_type))

Activity icon

Started a new Conversation Always Error When Migrating Table

i always getting error when migrating the create_password_resets_table. this migration originates from the original laravel. i never change the table structure to this table. but if i change to add length arround 100 from coulmn email

Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email',150)->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });

its not error.

why its need to modify. right now i using laravel 7

here from error

Illuminate\Database\QueryException

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'password_resets' already exists (SQL: create table password_resets (email varchar(150) not null, token varchar(255) not null, created_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

Activity icon

Replied to How To Delete All Data Relating To The Data To Be Deleted?

thank you i already use your sugesttion. its work.

Oct
21
1 week ago
Activity icon

Replied to How To Delete All Data Relating To The Data To Be Deleted?

this is the error: if i dont delete data from the pivot table, where the data are related. but if i delete data first from the pivot table, no error occur. i think i will try your suggestion. i will hit best answer if this work. thank you information about cascade.

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (pt_demo.absensi_karyawan, CONSTRAINT detailabsens_karyawans_id_foreign FOREIGN KEY (karyawan_id) REFERENCES karyawan (id)) (SQL: delete from karyawan where id = 2)

Activity icon

Started a new Conversation How To Delete All Data Relating To The Data To Be Deleted?

i dont know to explain it with clearly.

but i have case like this..

i have 3 tables

first is employees = id | name

second is attendanceDate = id | date

third is attendance_employees = employees_id | attendanceDate_id

if i delete 1 data from employees . it will also delete the effect of the data in attendance_employees. So, for example, I delete employees with id 1. All records for employee id 1 in attendance_employees are also deleted. because when I delete the employee id 1, but the employee id 1 data is still in the attendance_employees table, an error will occur. how to handle it? do I need settings on my database in mysql?

can you tell me the hint key about this ?

Activity icon

Replied to About $loop->iteration And Paginate

it works too, thank you.

Activity icon

Replied to About $loop->iteration And Paginate

thank you for respon @michaloravec i really appreciate it. i will give you love tags.

@sinnbeck i just choose who reply the first my question. hehehe and you the first person. if it not work it i will choose @michaloravec . bytheway are you getting some reward maybe to answer many question in this forum? i mean real reward..

Activity icon

Replied to About $loop->iteration And Paginate

if i click next page . the no contiune number 1,2,3,4,5

image

next page start from 2 it should be no 5,6,7,..

image

Activity icon

Started a new Conversation About $loop->iteration And Paginate

i already doing paginate(4)

and doing @foreach() $loop->iteration @endforeach

i want column No continue if i change to next page (paginate),

the detail code

<th scope="col">No</th>
@foreach ($attend as $data)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
...

my controller

$attend = Absensi::Paginate(4);
return view('attend.home',['attend'=>$attend]);
Activity icon

Replied to Want Add More Where Cluase

by theway how to quote replay like that?

Activity icon

Replied to Want Add More Where Cluase

I'm still trying your suggestions

Activity icon

Replied to Want Add More Where Cluase

thank you for respon, i still learning laravel to build a simple attandance_worker

Activity icon

Replied to Want Add More Where Cluase

i dont doing refresh until 7653, seriously. im noob programmer i dont know how to do that.

Activity icon

Started a new Conversation Want Add More Where Cluase

how i can add more where caluse

$attendance_worker = Attendance_worker::where('attendance_id', $id)->count();

i want add more where like this (information', '=', 'present', 'halfattend');

Activity icon

Started a new Conversation Its About Count()

i wanna to count() but i getting error liek this

Invalid argument supplied for foreach()

if i dd($variabel) its not error the variabel.

the code

$absensi_karyawan = Absensi_karyawan::where('absensi_id', '=', $id)->count();

and here for blade.php

@foreach ($absensi_karyawan as $a)
       total kehadiran : {{$a}}
 @endforeach
Oct
20
1 week ago
Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

Shouldn't this be related to the prize model?

class Member extends Model
{
    protected $table = "member";

    protected $fillable = [
        'name_member'
    ];

    public function prize()
    {
    	return $this->belongsToMany(Prize::class, 'Member_prize', 'member_id', 'prize_id');
    }
}

what should i do for solve this? please..

Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

its work now i wrong type the class model for the relation that

public function prize()
    {
    	return $this->belongsToMany(Member::class, 'Member_prize', 'member_id', 'prize_id');
    }

its should be Prize::class

heheh but i have problem now the view form dropdown menu is getting doble for some item. how to make it not doble? image

Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

its look like this. but if i count the marked blue like that until down. the total is same as my table prize data. image

Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

member model

class Member extends Model
{
    protected $table = "member";

    protected $fillable = [
        'name_member'
    ];

    public function prize()
    {
    	return $this->belongsToMany(Member::class, 'Member_prize', 'member_id', 'prize_id');
    }
}

and than the controller

public function create()
    {
        $members = Member::with('prize')->get();
        return view('create', ['member' => $members ]);
    }
Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

actually its not yet solve now. I unconsciously pushed that button. please help me..

the view not have error but, the dropdown option only blank..

Oct
19
1 week ago
Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

if i doing with nested the foreach it will like this

<select name="nama_hadiah" type="text" class="form-control">
                    <option selected> choose prize here</option>
                    @foreach($member as $a)
                        @foreach($a->prize as $ab)
                        <option value="{{$ab->id}}">{{ $ab->name_prize }}</option>
                        @endforeach
                    @endforeach
                    </select>

there no error. but the result for drop down no option. just blank dropdown .

Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

i want first select member and than select prize for member and than after i submit it will save to Member_prize model.

for example:

member A get prize A in Member_prize will save member_id :1 (A) and prize_id 1 (A)

member A get prize B in Member_prize will save member_id: 1 (A) and Prize_id 2 (B)

member B get prize A in Member_prize will save member_id: 2 (B) and Prize_id 1 (A)

memeber C get prize B in member_prize will save member_id: 3 (C) and Prize_id 2 (B)

Activity icon

Replied to Property [ ] Does Not Exist On This Collection Instance

it still not working.

the error still same. i already change variable names to english and table name.

public function create()
    {
        $members = Member::with('prize')->get();
        return view('create', ['member' => $members ]);
    }

actually i have 2 form like this

<label> Pilih nama </label>
                    <select name="nama_hadiah" type="text" class="form-control">
                    <option selected> choose prize here</option>
                        @foreach($member as $a)
                        <option value="{{$a->id}}">{{ $a->name_member }}</option>
                        @endforeach
                    </select>
                    <label class="mt-3"> Pilih hadiah </label>
                    <select name="nama_hadiah" type="text" class="form-control">
                    <option selected> choose prize here</option>
                    @foreach($member->prize as $ab)
                    <option value="{{$ab->id}}">{{ $ab->name_prize }}</option>
                    @endforeach
                    </select>

Member model

public function prize()
    {
    	return $this->belongsToMany(Member::class, 'Member_prize', 'member_id', 'prize_id');
    }
Activity icon

Started a new Conversation Property [ ] Does Not Exist On This Collection Instance

why i getting error like = this Property [hadiah] does not exist on this collection instance.

i have already add this in model

public function hadiah()
    {
    	return $this->belongsToMany('App\Hadiah');
    }

and my view

@foreach($anggota->hadiah as $ab)
      <option value="{{$ab->id}}">{{ $ab->nama_hadiah }}</option>
@endforeach

and my Controller

$anggota = Anggota::get();
return view('create', ['anggota' => $anggota ]);
Oct
18
1 week ago
Activity icon

Replied to I Have Case About Views And Relation Eloquent Please..

mr sinnbeck im so sorry. Can you help me sir?

Activity icon

Replied to I Have Case About Views And Relation Eloquent Please..

if i doing add new member in "anggota" table (id:7 name:meglo). imgae

i want to save new data in table ("anggota_hadiah") with $request form with that new member (id=7, name=meglo + hadiah_id= 1, which mean it will be filled like this in the table "anggota_hadiah" table)

image

so if i doing form $request view in create.blade.php

<form role="form" action="/store" method="POST" enctype="multipart/form-data">
                <div class="form-group">
                        <input name="_token" type="hidden" value="{{ csrf_token() }}" />
                        <input name="_method" type="hidden" value="POST" />
                </div>
                <div class="form-group row col-md-3">
                <label> name </label>
                <select name="nama" type="text" class="form-control">
                <option selected> choose name mamber here</option>
                    @foreach($angotta as $a)
                    <option value="{{$a->id}}">{{ $a->nama }}</option>
                    {{-- This part Form should store in anggota_hadiah table witch ex: anggota_id : 7 (meglo) --}}
                    @endforeach
                </select>
                </div>

                <div class="form-group row col-md-3">
                <label> Prize </label>
                <select name="nama_hadiah" type="text" class="form-control">
                <option selected> choose prize here</option>
                    @foreach($angotta as $a)
                    <option value="{{$a->id}}">{{ $a->hadiah->nama_hadiah }}</option>
                    {{-- This part Form should store in anggota_hadiah table, ex: hadiah_id: 1 (kulkas) --}}
                    @endforeach 
                </select>
                </div>
            <button type="submit" class="btn btn-primary waves-effect">Add Data</button>
            </form>

Same as picture above @foreach($angotta as $a)<option value="{{$a->id}}">{{ $a->nama }}</option>{{-- This part Form should store in anggota_hadiah table witch ex: anggota_id : 7 (meglo) --}}@endforeach and @foreach($angotta as $a)<option value="{{$a->id}}">{{ $a->hadiah->nama_hadiah }}</option>{{-- This part Form should store in anggota_hadiah table, ex: hadiah_id: 1 (kulkas) --}} @endforeach i want it store in "anggota_hadiah" table

and my controller

public function create()
    {
        $angotta = Anggota::get();
        return view('create', ['angotta' => $angotta ]);
    }

    public function store(Request $request)
    {
    Anggota::create($request->all());
    return redirect('anggota');
    }

and my route

Route::get('/anggota', '[email protected]');
Route::get('/create', '[email protected]');
Route::post('/store', '[email protected]');

and i add $fillable in model anggota_hadiah.php

protected $table = "anggota_hadiah";

    protected $fillable = ['anggota_id', 'hadiah_id'];

    public function anggota()
    {
        return $this->belongsToMany('App\Anggota');
    }

    public function hadiah()
    {
        return $this->belongsToMany('App\Hadiah');
    }

how do you think mr.sinnback? there must be a lot of things wrong

Activity icon

Replied to I Have Case About Views And Relation Eloquent Please..

Sorry again and thank you for responding Mr. Sinnback. In the future I want to do CRUD in the table "anggota_hadiah (model:Anggota_hadiah.php)"

like this example if i doing insert: I enter the name of the member, and then I enter the prize. Isn't it only possible to do CRUD in the table anggota_hadiah (model: Anggota_hadiah.php)? if I do and call the "Anggota.php" model in the controller as suggested $angotta = Anggota::get(); , can I still do CURD on the Member_hadiah.php model?

sorry for my nescience and my stupidity

Activity icon

Started a new Conversation I Have Case About Views And Relation Eloquent Please..

hello excuse me, sorry to disturb the time sir/master/instructor, im newbe and still learning now about laravel.

i have case like this i want doing CRUD my "anggota_hadiah.php" table but before CRUD i want which can display the contents of the member's name in option tag in my create.blade.php. i want doing CRUD on the model "anggota_hadiah.php"

i have 3 tables in my Database. first is "anggota" this table collect name's member (nama). Image

and the second is "anggota_hadiah" this table collect anggota_id and hadiah_id Image

and the third is "hadiah" this table collect hadiah (in english its mean name's prize) Image

this is my views file "create.blade.php"

<form action="">
                <label> name </label>
                <select name="j_kel" type="text" class="form-control">
                <option selected> choose name mamber here</option>
                    @foreach($create as $a)
                        <option>{{ $a->anggota_id }}</option>
                    @endforeach
            </form>

from the code above. i want in the code @foreach($create as $a)<option>{{ $a->anggota_id }}</option>@endforeach can show the nama(name's mamber) from the table anggota. my controller for this function is like this

public function create()
    {
        $create_form = Anggota_hadiah::get();
        return view('create', ['create' => $create_form]);
    }

so if i doing click in view option to choose name's member its only show the name from anggota table and the name in option is not repeated like this anggota_id.

Image

and my model are like this:

  1. Anggota.php
class Anggota extends Model
{
    protected $table = "anggota";

    public function hadiah()
    {
    	return $this->belongsToMany('App\Hadiah');
    }
}
  1. Hadiah.php
class Hadiah extends Model
{
    protected $table = "hadiah";

    public function anggota()
    {
    	return $this->belongsToMany('App\Anggota');
    }
}

3.Anggota_Hadiah.php

class Anggota_hadiah extends Model
{
    protected $table = "anggota_hadiah";

    public function anggota()
    {
        return $this->belongsToMany('App\Anggota');
    }

    public function hadiah()
    {
        return $this->belongsToMany('App\Hadiah');
    }
}

im so sorry my english not well. but i try to learn from this case. Please help me. i really need help..

Oct
16
1 week ago
Activity icon

Replied to About Relationship, And View

sorry i already update it

Activity icon

Started a new Conversation About Relationship, And View

here my code :

  1. migration

    (1)migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAbsensisTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('absensis', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('tanggal');
            $table->timestamps();
        });

        if (Schema::hasTable('detailabsens')) {
            Schema::table('absensis', function (Blueprint $table) {
                $table->foreign('detailabsens_id')->references('id')->on('detailabsens');
            });
        };

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('absensis');
    }
}

(2) migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDetailabsensTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('detailabsens', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->foreignId('karyawans_id');
            $table->foreignId('absensis_id');
            $table->time('time_in');
            $table->time('time_out');
            $table->timestamps();
        });

        Schema::table('detailabsens', function (Blueprint $table) {
            $table->foreign('karyawans_id')->references('id')->on('karyawans');
        });

        Schema::table('detailabsens', function (Blueprint $table) {
            $table->foreign('absensis_id')->references('id')->on('absensis');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('detailabsens');
    }
}

my route

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });


Route::get('/home', function () {
    return view('main');
});

Route::get('/dashboard', '[email protected]');

Route::get('/home', '[email protected]');

Route::get('/karyawan', '[email protected]');
Route::get('/karyawan/create', '[email protected]');
Route::post('/karyawan/store', '[email protected]');
Route::get('/karyawan/{karyawan}/edit', '[email protected]');
Route::put('/karyawan/{karyawan}', '[email protected]');
Route::delete('/karyawan/{karyawan}', '[email protected]');


Route::get('/absensi', '[email protected]');
Route::post('/absensi/store', '[email protected]');
Route::get('/absensi/create', '[email protected]');

my controller

<?php

namespace App\Http\Controllers;

use App\Detailabsen;
use App\Absensi;
use Illuminate\Http\Request;

class AbsensisController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('absensi.home');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
    Absensi::create($request->all());
    return redirect('/absensi')-> with('status', 'Tanggal berhasil di tambahkan');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function createabsen()
    {
        $absensi = Detailabsen::all();
        return view('absensi/create',['absensi'=>$absensi]);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Absensi  $absensi
     * @return \Illuminate\Http\Response
     */
    public function show(Absensi $absensi)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Absensi  $absensi
     * @return \Illuminate\Http\Response
     */
    public function edit(Absensi $absensi)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Absensi  $absensi
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Absensi $absensi)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Absensi  $absensi
     * @return \Illuminate\Http\Response
     */
    public function destroy(Absensi $absensi)
    {
        //
    }
}

my model

(Absensi.Php)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Absensi extends Model
{

    protected $fillable = ['tanggal'];

    public function detailabsen() {
        return $this->belongsTo('App\Detailabsen');
    }
}

(Detailabsen.Php)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Detailabsen extends Model
{
    // protected $table = 'detailabsens';
    protected $fillable = ['time_in', 'time_out'];

    public function absensis() {
        return $this->hasMany('App\Absensis');
    }
}

and this my view

create.blade.php


@extends('layouts.master')

@section('content-header')
<div class="row">
    <div class="col-xl-12">
        <div class="card easion-card">
            <div class="card-header">
                <div class="easion-card-icon">
                    <i class="fas fa-chart-bar"></i>
                </div>
                <div class="easion-card-title"> Absensi Karyawan </div>

@endsection

@section('content')
                </div>
@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif
    <div class="card-body ">
        <form role="form" action="/absensi/store" method="POST" enctype="multipart/form-data">
            <div class="form-group">
                <input name="_token" type="hidden" value="{{ csrf_token() }}" />
                <input name="_method" type="hidden" value="POST" />
            </div>
            <div class="form-group row col-md-3">
                <label> Tanggal Absen </label>
                <select name="tanggal" type="text" class="form-control @error('tanggal') is-invalid @enderror" placeholder="Pilih Tanggal" value="{{ old('tanggal') }}"> 
                    @foreach ( $absensi as $data)
                        <option value="{{$data->absensis_id}}">{{$data->tanggal}}</option>
                        //i want show the option from this form shows data table from column "$table->date('tanggal');"//
                    @endforeach
                </select>
                @error('tanggal')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
            <button type="submit" class="btn btn-primary waves-effect">Input Absen</button>
        </form>
    </div>
@endsection

sorry, my question

for my view create.blade.php i want show the option value form shows data table from column "$table->date('tanggal').

Activity icon

Replied to Migration Error

thank you its work!

Activity icon

Started a new Conversation Migration Error

the error

Class 'CreateKaryawansTable' not found

at D:\PT_demo\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:453

449| public function resolve($file)

450| {

451| $class = Str::studly(implode('', array_slice(explode('', $file), 4)));

452|

453| return new $class;

454| }

this is my migration table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateKaryawanTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('karyawans', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('nama_kyn', 30);
            $table->date('tgl_lahir');
            $table->string('j_kel', 10);
            $table->text('alamat');
            $table->char('no_tlp', 13);
            $table->date('join_date');
            $table->date('end_date')->nullable();
            $table->string('status', 10);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('karyawan');
    }
}
Oct
10
2 weeks ago
Activity icon

Replied to Succeed To Redirect View, But Database Not Update.

thank you , it works. haa... i can sleep well now..

Activity icon

Replied to Succeed To Redirect View, But Database Not Update.

oh my god it works, from the bottom of my heart I say thank you very much, I almost 24 hours just looking for this. I like this forum fast response. sorry I am still a beginner.

oia, I still don't understand what he means about validation, I've made a request form via the terminal.

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class KaryawanValidation extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [

                'nama_kyn' => 'required',
                'tgl_lahir' => 'required|date',
                'j_kel' => 'required',
                'alamat' => 'required',
                'no_tlp' => 'required|numeric',
                'join_date' => 'required|date',
                'status' => 'required',
        ];



    }

    public function messages()
    {
        return [
                    'nama_kyn.required' => 'Kolom nama harus di isi!',
                    'tgl_lahir.required' => 'Kolom alamat harus di isi!',
                    'tgl_lahir.date' => 'isi tanggal lahir yang benar!',
                    'j_kel.required' => 'isi dengan L(laki-laki), P(perempuan)!',
                    'alamat.required' => 'kolom alamat harus di isi!',
                    'no_tlp.numeric' => 'No Telpon harus di isi dengan angka!',
                    'no_tlp.required' => 'kolom harus di isi!',
                    'join_date.required' => 'Join Date harus di isi!',
                    'join_date.date' => 'Isi tanggal yang benar!',
                    'status.required' => 'Status Harus di isis yang benar!',
        ];
    }

is it right? if it right how to use in my form view in edit.blade.php?

Activity icon

Replied to Succeed To Redirect View, But Database Not Update.

i getting error

BadMethodCallException Call to undefined method App\Karyawan::udpate() http://127.0.0.1:8000/karyawan/1