amrcodes

Member Since 2 Months Ago

Experience Points
2,880
Total
Experience

2,120 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
26
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.

  • Community Pillar

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

Level 1
2,880 XP
Feb
21
1 week ago
Activity icon

Replied to Multiple Sections!

Usually I receive the request inside my store function like this

$guest->guest_name = $request->guest_name;

so is it going to be something like this:

$guest->guest_name = $request->guest_name[$i];
Activity icon

Replied to Multiple Sections!

Thanks for your respond Snapey!

I did this as you explained but I'm confused how to deal with it inside the controller

like the requests from each section how to handle them in my controller!

Again thanks for helping!

Activity icon

Started a new Conversation Multiple Sections!

Any idea how to deal with the following scenario?

I made a JS script that generates multiple sections up to 10 sections each section have identical inputs for details.

So, when the user select x amount of sections, the script generates the entered amount of sections. [Each section is identical]

When I try to receive this data from the sections to my database I only receive 1 section data.

I'm trying to think of a way to help passing all the data from these identical sections to the db.

https://ibb.co/r3zb94q

Feb
18
2 weeks ago
Activity icon

Started a new Conversation Inserting Data To Two Tables [one To Many]

Hello, I'm new to laravel and I'm struggling with a problem for almost 3 days,

I have two tables first table = customer_info [primary key] main table second table = room_info [foreign key]

when I insert new data to the table room_info using the foreign key a new row is created inside of the customer_info with a new id but nothing happens inside of the 2nd table room_info because I don't know how to use foreign key inside of my controller room_info table

I'm not using migrations I use PHPMyAdmin here is my code:

Controller for the rooms table=

<?php

namespace App\Http\Controllers;
use \Debugbar;
use Illuminate\Http\Request;
use App\Models\Room;
use App\Models\Customer;

class GuestRoomController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $cat = Customer::all();
        return view('guest')->with('cat', $cat);
        
    }

    /**
     * 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)
{
        $room = new Room;
        $room->room_nums = $request->room_num;
        $room->room_type = $request->room_type;
        $room->adults = $request->adults;
        $room->child = $request->child;
        $room->user_id = 44;
        // dd($room->id);
        $room->save();
        return redirect('/guest');

        
        
    }

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

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

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
controller for the customer_info
<?php

namespace App\Http\Controllers;
use App\Models\Guest;
use App\Models\Customer;
use App\Models\Info;

use Illuminate\Http\Request;

class GuestController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // $guest = Guest::all();
        // return view('guest')->with('guest', $guest);
        // dd($guest);
    }

    /**
     * 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)
    {
        $guest = new Customer;
        $guest->guest_name = $request->name;
        $guest->nationality = $request->nationality;
        $guest->email = $request->email;
        $guest->mobile_num = $request->mobile;
        // $guest->id = $request->id;

        // $guest->nationality = $request->nationality;
        // $guest->nationality = $request->nationality;
        $guest->save();
        return redirect('/res');
    }

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

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

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
room model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Room extends Model
{
    use HasFactory;
    public $timestamps = false;
    protected $table = 'booking_guest_room';
    protected $fillable = ['user_id', 'id'];
    public function rooms(){
        return $this->belongsTo(Customer::class);
    }

}
customer model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    use HasFactory;
    protected $table="customer_info";
    public function customers(){
        return $this->hasMany(Room::class);
    }
}
route file
<?php

use App\Http\Controllers\InfoController;
use App\Http\Controllers\GuestController;
use App\Http\Controllers\GuestRoomController;
use Illuminate\Support\Facades\Route;
// use App\Http\Controllers\PackageController;
/*
|--------------------------------------------------------------------------
| 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('sections', function(){
    return view('sections');
});
Route::get('res', function(){
    return view('res');
});

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


Route::resource('guest', GuestController::class);
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

how to do it if use resources controller like Route::resource('guest', GuestController::class);

Activity icon

Replied to Foreign Key Doesn't Have A Default Value

Yes exactly but I don't how to translate this to the code

Activity icon

Replied to Foreign Key Doesn't Have A Default Value

This is the blade where I enter the room info and submit it

                <div class="step">
                    <form  method="post" action="{{route('res.store')}}">            
                        @method('POST')
                        @csrf
                    <div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="form-group">
                                <table class="table table-striped table-inverse table-responsive form" >
                                    <thead class="thead-inverse">
                                        <tr class="w-5">
                                            <!-- <th>Room NO.</th> -->
                                            <th>نوع الغرفة</th>
                                            <th>الكبار</th>
                                            <th>الاطفال</th>
                                            <!-- <th>Child Ages</th> -->
                                            <th>احذف الغرفة</th>
                                        </tr>
                                        </thead>
                                    <tbody id='myTable'>
                                    {{-- here goes the table info --}}
                                    </tbody>
                                    <button class="add rounded btn btn-danger " type="button">اضف الغرفة</button>
                                    <!-- <button class="remove">Remove Room</button> -->
                                    <input type="number" class="numbers" value="" name="room_num" min="0" placeholder="عدد الغرف">
                                </table>
                            </div>
                        </div>
                        
                    </div>
                    <input type="number" name="user_id" id="" value="{{$room->id}}">

                    <hr>

                    <button class="btn btn-info" >Book now</button>
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

This is the guest info model

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Guest extends Model
{
    
    use HasFactory;
    protected $table = 'customer_info';
    public $timestamps = false;
    


   
}
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

This is the room info model

class Room extends Model
{
    use HasFactory;
    public $timestamps = false;
    protected $table = 'booking_guest_room';
    protected $fillable = ['user_id', 'id'];

    public function rooms(){
        return $this->hasMany(Room::class, 'user_id');
    }
}
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

This is the guest_info controller

    {
        $guest = new Guest;
        $guest->guest_name = $request->name;
        $guest->nationality = $request->nationality;
        $guest->email = $request->email;
        $guest->mobile_num = $request->mobile;
        $guest->save();
        return redirect('/res');
    }```
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

This is the GuestRoom controller which contains the user room info

`public function store(Request $request) {

    $room = new Room;
    $room->room_nums = $request->room_num;
    $room->room_type = $request->room_type;
    $room->adults = $request->adults;
    $room->child = $request->child;
    
    dd($room->id);
    $room->save();
    return redirect('/guest');
    
}
Activity icon

Replied to Foreign Key Doesn't Have A Default Value

Sorry I can't describe what I really need to do good it feels like the steps are not organized in my brain, here is the code here is model for booking_guest_info table https://pasteboard.co/JOU6MbQ.png here is my model for customer_info table https://pasteboard.co/JOU7Gjr.png here is my controller for booking_guest_info https://pasteboard.co/JOU86Ky.png also this is the guest_info controlloer https://pasteboard.co/JOU8rlQ.png

Activity icon

Replied to Foreign Key Doesn't Have A Default Value

Thank you but, this is inserting the guest_id to the controller manually! How can I pass it automatically to match the entered data, what I'm trying to say is if I want add new row inside the booking_guest_room that relates to a user inside the customer_info table what should so that once I insert the data inside the booking_guest_room it creates automatically a new id inside the customer_info?

Activity icon

Replied to Foreign Key Doesn't Have A Default Value

sorry user_id, but I'm a bit confused I'm not sure how to insert the value of the foreign id to the new data!

Activity icon

Replied to Foreign Key Doesn't Have A Default Value

here is model for booking_guest_info table https://pasteboard.co/JOU6MbQ.png here is my model for customer_info table https://pasteboard.co/JOU7Gjr.png here is my controller for booking_guest_info https://pasteboard.co/JOU86Ky.png also this is the guest_info controlloer https://pasteboard.co/JOU8rlQ.png

I don't use migrations as I need to learn it more so I use phpmyadmin

Activity icon

Started a new Conversation Foreign Key Doesn't Have A Default Value

Can I get help with the foreign key problem?

I have two tables that I created on PHPMyAdmin the first table is customer_info the second table is booking_guest_room I created a foreign key [user_id] in the booking_guest_room I added fillable for user_id but when I try to store new data for booking_guest_room it throws an error "user_is doesn't have a default value"

I'm struggling with this problem for 3 days and I'm not sure what I'm doing wrong. Sorry for my weak English https://cdn.discordapp.com/attachments/486650445297877003/811889719243440128/unknown.png