lundi 2 septembre 2019

How to alter onDelete('RESTRICT') to CASCADE

In laravel 5.8 app I create a migration with table :

{
    Schema::create('reserves', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('storage_space_id')->unsigned()->nullable();
        $table->foreign('storage_space_id')->references('id')->on('storage_spaces')->onDelete('RESTRICT');

        $table->decimal('vat', 12, 2)->nullable();
        ...
        $table->timestamp( 'created_at')->useCurrent();

        $table->index(['storage_space_id', 'reserve_date'], 'reserves_storage_space_id_reserve_date_index');
        $table->index(['storage_space_id', 'reserve_out_date'], 'reserves_storage_space_id_reserve_out_date_index');

    });
}

and now deleting row from storage_spaces I get “Integrity constraint violation” error when there are related rows in reserves. I know that I need to alter onDelete to “CASCADE”, but I do not can in be done with migration ? If yes how ?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Zw9smr
via IFTTT

Retrieve recording of a user after login

I have a table named Student with several fields :

'id', 'user_id', 'name', 'firstname', 'date_birth', 'sex', 'address', 'fk_city', 'phone', 'email', 'status', 'fk_license', 'date_registration'.

I have another table named Feedback with several fields also:

'id', 'user_id','instruction', 'description', 'fk_student'.

I also have 2 roles which are Admin and Member.

The administrator creates 2 recordings in the table Student, see below:

enter image description here

And the administrator creates 1 recording in the table Feedback for the Student Menier Jeremy.

enter image description here

When, I login with the address email test@gmail.com (Menier Jeremy) I see my 2 rubrics: (Student profil and feedback)

enter image description here

I can consult my information in my profil

enter image description here

Well!

Now, my problem is that when I click on my Feedback to consult the Feedback; it's empty ?

enter image description here

I don't understand why I retrieve the information for the rubric Student and no for the rubric Feedback?

Here is an idea of my code, is it a problem with my model?

public function index(Request $request)
    {   
    $user = $request->user();

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        $query->whereHas('user', function ($query) use ($user) {
            $query->where('email', $user->email);
    });
    })
    ->when($request->has('search'), function (Builder $query) use ($request) {
     $query->join('students', 'feedbacks.fk_student', '=', 'students.id')->orderBy('students.name', 'asc')->where('students.name','like','%'.$request->input('search').'%');
     })
    ->paginate(5);

    return view('admin.feedbacks.index', compact('feedbacks'))
        ->with('display_search', $user->hasRole('admin'));
}

Thank you for your help.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LgMxmr
via IFTTT

how to transfer by a Website created on laravel through cpanel without having any error

i have a website which is created (not by me) on laravel . i download every thing from existing hosting . Then i uploaded to another free webhosting services for educational purpose. but i am getting a error " Whoops, looks like something went wrong" .

before path was /home/gry - (folder like app,bootstrap,config,database....) and /home/public_html -(indexpage , assets ...etc)

and there is .htacess file which have rewrite function

Newer path was /home/htdocs/gry and /home/htdocs/public_html

i already tried to edit index path "require DIR.'/../gry/bootstrap/autoload.php'; " to require DIR.'/../../gry/bootstrap/autoload.php'

also same to bootstrap/app.php

still i am getting the error " Whoops, looks like something went wrong" . , can you tell me step by step what i have to do , or if u need some files to check i can attach



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2lPY0Pr
via IFTTT

Laravel eloquent/collection select only matching records for all requested users

I have a polymorphic "Relationships" many to many relation that looks like that:

users
id | first_name | last_name

groups
id | group_name

regions
id | region_name

relationships
id | user_id | relationship_id | relationship_type | relationship_level
 4 |      13 |              25 |         App\Group |      Group Manager
 5 |      20 |              18 |        App\Region |        Participant

And the relationship looks like that:

public function regions()
{
    return $this->morphedByMany('App\Region', 'relationship')->withPivot('relationship_level')->withTimestamps();
}

public function groups()
{
    return $this->morphedByMany('App\Group', 'relationship')->withPivot('relationship_level')->withTimestamps();
}

And vice versa.

When I have an array of IDs, I want to select the relationships that exactly match between the users, this means that all columns (except user_id) match.

And they should only be rows that match among all users. If only 10 out of 12 selected users have the same relationship it should not be included.

If I select 10 users I need to select a pivot record that all those 10 users have (if any).

It doesn't matter if done in eloquent or via the collection after fetching from Database.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2lrVjTT
via IFTTT

Laravel - mariaDB connection refused

On my new laptop, i've windows 10 with ubuntu bash. mariadb 10.1 working fine and trying to config my laravel projects. But when i try to login on laravel 5.6 i get the message: "Connection refused"

I try into DB_HOST my local IP and 127.0.0.1 I checked all connections, clean cache from laravel, try connection to mysql from command line.

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=root

Ideas?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2lSjvPM
via IFTTT

I want to issue a validation error message

I registered an error message but I don't know how to output it
WorkController.php

public function store(CreateWorkRequest $request,$id)
{
    $v = $request->WorkRequest();
    return redirect()->route('work.index', ['id' => $id]);
}

CreateWorkRequest

public function rules()
{
    return [
        'work_time' => 'required',
        'content' => 'required',
    ];
}
public function messages() {
    return [
        'work_time' => ':Required',
        'content    ' => ':Required',
    ];
}

I would like to know where to edit



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2km76TD
via IFTTT

FormRequest managing extra actions

I have a multi-step form and each step with its own FormRequest for validating fields.

All works fine but I need to make some extra actions in case one field is not validated.

So, if the FormRequest results in an error, the controller is bypassed and returned to the view showing errors.

In my case, I have a validation rule for title. In case title exists in database, i need to run some extra php code.

How can i accomplish this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2km72mR
via IFTTT