samedi 7 mai 2022

Undefined variable in boostrap modal - Laravel

I have a $room variable inside a bootstrap modal and it is causing the problem here is the function in the reservationController

    {
        $room=Room::all();
        return view('/allReservationChild', compact('room'));
    }

the blade name is allReservationChild.blade.php and this is the part of the modal :

```<div class="modal fade" id="addres" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Delete Room</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form style="margin: 50px; text-transform: capitalize " action="/addReservation" method="POST" class="needs-validation" novalidate >
                @csrf

                <div class="modal-body">
                    <div class="form-group">
                        <label for="exampleFormControlSelect1">Select the Room you want to reserve</label>
                        <select class="form-control" id="exampleFormControlSelect1" name="room_id" required>
                            <option value=""></option>
                            @foreach($room as $items)
                                <option value=""></option>
                            @endforeach

                        </select>
                    </div>


                    <div class="mb-3">
                        <label for="exampleFormControlTextarea1" class="form-label">Objectif :</label>
                        <select class="form-control" id="exampleFormControlTextarea1" name="objectif" required>
                            <option value=""></option>
                            <option value="Booking room for a replacement session ">Booking room for a replacement session </option>
                            <option value="Booking room for a random session">Booking room for a random session</option>
                            <option value="Booking room for an event">Booking room for an event</option>
                            <option value="Booking room for an exam">Booking room for an exam</option>
                            <option value="Booking room for discussion of the graduation thesis">Booking room for discussion of the graduation thesis</option>
                            <option value="other">other</option>
                        </select>
                    </div>


                    <div class="form-group">
                        <label class="control-label">Reservation date</label></br>
                        <input class="form-control" type="date" id="Date_beginning" name="date" required>
                    </div>

                    <div class="form-group">
                        <label for="time">Select time period</label>
                        <select class="form-control" id="time" name="time" required>
                            <option value=""></option>
                            <option value="8:30-10:30">8.30-10.30</option>
                            <option value="10:30-12:30">10.30-12.30</option>
                            <option value="13:30-15:30">13.30-15.30</option>
                        </select>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-outline-danger" name="supp" >Add Reservation</button>
                </div>
            </form>

        </div>
    </div>
</div>

and for the **web** 

 ```Route::get('/addReservation',[\App\Http\Controllers\reservationController::class,'create']);

I don't know why ha can not know define the $room variable I think it is because of the modal or something. and the modal I'm sure it is right because I used the same modal in another blade and it works perfectly so the problem I think is in the controller or the web I am not sure



via Chebli Mohamed

The url redirection is not working properly in laravel

Any false url redirecting to home page in my laravel site. It is required to be redirected to 404 page.



via Chebli Mohamed

jeudi 5 mai 2022

concatenate two values in register

I am modifying a register page, I need to concatenate two values

UI

<div class="col-xs-12 col-md-3 input-group">
    <input name="tomo" type="text" class="form-control" placeholder="Tomo" required autocomplete="off">
    <span style="font-size: 25px; color: #bfc9d4;" class="input-group-addon"> --- </span>
    <input name="folio" type="text" class="form-control" placeholder="Folio" required autocomplete="off">
</div>

The values are tomo and folio

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        't_matricula' => ['required', 'string', 'max:255'],
        'matricula' => ['required', 'string', 'max:255'],
        'password' => ['required', 'string', 'min:8', 'confirmed'],
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        't_matricula' => $data['t_matricula'],
        'numero' => rand(100, 9200),
        'matricula' => $data['tomo'] . $data['folio'],
        'password' => Hash::make($data['password']),
    ]);

    Mail::to($user->email)->send(new WelcomeMail($user));

    return $user;
}

I must save the tomo and folio values in the matricula field, the problem is that it does not execute the registry, please help.



via Chebli Mohamed

mercredi 4 mai 2022

You do not have the SUPER privilege and binary logging is enabled

I am running a laravel migration from jenkins that creates a stored procedure and the following error appears:

SQLSTATE[HY000]: General error: 1419 You do not have the SUPER privilege an  
  d binary logging is enabled (you *might* want to use the less safe log_bin_  
  trust_function_creators variable) (SQL:                                      
              CREATE TRIGGER ...

How can I fix this and allow the migration to create triggers, etc. without problems.



via Chebli Mohamed

Undefined class constant 'MAIN'

We have the following migration:

class CreateAccounts extends Migration
{

    public function up()
    {
        $data= [
            "id" => \App\Account::MAIN,
            "container" => null,               
        ];

        \App\Account::create($data);
    }

}

And here is the class Account, it contains some constants and methods:

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;

    class Account extends MainModel
    {
        const MAIN = 47;
    
    ...
    
    }

The migration works fine in our dev server but on production it complaints saying

Undefined class constant 'MAIN'

The same error from tinker.



via Chebli Mohamed

lundi 2 mai 2022

how to use whereHas in laravel

I am new to laravel, I need to create a query for the db,

 $query = Deal::query();

I want to use the wherehas operator. this is my code that is worked.

else if ($group_by == 'precedence') {
                if($get_deals_for == 'noprecedence'){
                    $get_deals_for = 0;
                }
                $precedenceStatus = $get_deals_for;
                $query-> where('precedence', '=', $precedenceStatus);
            //    \Log::info('The request precedence: '.$precedenceStatus);
               

            }

I want to add this code also to the query

if($person) {
                    $query->whereHas('personnel', function ($subQuery) use ($person) {
                        $subQuery->where('id', '=', $person);
                    });
                }

So I need to change the first code? how I can convert the first code to wherehas? the first code is from table called deal, the second section is from realtionship called personnel. the second section worked in other places in the code, I just need to fix the first section and not understand what to write in the use



via Chebli Mohamed

how can prevent user to use same token in laravel?

I have created api based web application..Actually I am able to login my lower level user as higher level user when I pass higher level user's token to lower level user.I have used cookie to authenticate user.



via Chebli Mohamed