dadub

dadub

Member Since 2 Years Ago

Experience Points
1,350
Total
Experience

3,650 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
3
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,350 XP
Jul
29
1 week ago
Activity icon

Awarded Best Reply on Add OrderBy To A ::with

Hello,

I just want to let you know that I used another way :

@foreach ($herb->hinteractions->sortBy('force_id') as $hinteraction)

I used sortBy in the view....

Thank you agian for your help.

Jul
28
1 week ago
Activity icon

Replied to Add OrderBy To A ::with

Hello,

I just want to let you know that I used another way :

@foreach ($herb->hinteractions->sortBy('force_id') as $hinteraction)

I used sortBy in the view....

Thank you agian for your help.

Jul
25
1 week ago
Activity icon

Replied to Add OrderBy To A ::with

Sorry, I added by mylsef.

But the problem is going on :

Undefined constant 'App\Http\Controllers\herbs'.intelephense(1011)

Activity icon

Replied to Add OrderBy To A ::with

Hello

Thank you, both of you.

I tried this code :

$herb = Herb::with('hinteractions.herbs', 'hinteractions.effects', 'hinteractions.targets');
        ->select(herbs.*)
        ->join('hinteractions as hi', 'hi.herb_id','=','herbs.id')
        ->orderBy('hi.force_id')
        ->findOrFail($id);

syntax error, unexpected '->' (T_OBJECT_OPERATOR) Undefined constant 'App\Http\Controllers\herbs'.intelephense(1011) Peek Problem (⌥F8) No quick fixes available

Thank you again for your help.

Activity icon

Started a new Conversation Add OrderBy To A ::with

Hello and thank you in advance for your help.

I have this code :

$herb = Herb::with('hinteractions.herbs', 'hinteractions.effects', 'hinteractions.targets')->findOrFail($id);

I would like to add orderBy force_id

App\Herb {#1783
  #relations: array:1 [▼
    "hinteractions" => Illuminate\Database\Eloquent\Collection {#1822 ▼
      #items: array:35 [▼
        0 => App\Hinteraction {#1851 ▼
          #table: "hinteractions"
          #attributes: array:9 [▼
            "id" => 157
            "herb_id" => 8
            "target_id" => 2
            "user_id" => 2
            "force_id" => 4
            "validated" => 1
            "created_at" => "2020-07-25 09:24:08"
            "updated_at" => "2020-07-25 09:24:08"
          ]

I tried that :

$herb = Herb::with('hinteractions.herbs', 'hinteractions.effects', 'hinteractions.targets')->orderBy('force_id')->findOrFail($id);

I have this error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'force_id' in 'order clause' (SQL: select * from herbs where herbs.id = 8 order by force_id asc limit 1)

Thank you in advance for your help.

Jul
22
2 weeks ago
Activity icon

Started a new Conversation Blocking A Multi-origin Request (Cross-Origin Request)

Hello everybody and thank you in advance for your help,

I use a datatable https://datatables.net/ for my laravel site.

I have this error message :

DataTables warning: table id=example1 - Ajax error. For more information about this error, please see http://datatables.net/tn/7

and this error in my web console (firefox) :

Blocking of a cross-origin request: the “Same Origin” policy does not allow consulting the remote resource located on http://cdn.datatables.net/plug-ins/1.10.20/i18n/French .json. Reason: The "x-csrf-token" header is not allowed according to the "Access-Control-Allow-Headers" header of the CORS request pre-check response.

This is the controller code :

        if($request->ajax()) {
            $query = Drug::with('drug_family','routes','atc','user')->select('drugs.*');

        return DataTables::eloquent($query)->toJson();
        }
        return view('errors.layout');

    }

I think I don't have any problem in my code, because with php artisan serve, I can display the datatable.

With MAMP (in local) I cannot display it.

Do you think it's a problem of security ?

Do you have any idea to resolve it ?

Thank you in advance for your help.

Jul
15
3 weeks ago
Activity icon

Started a new Conversation Regex To Delete Lines Begining With Username (MS Visual Studio Code)

Hi everybody,

I would like to create a regex to select all lines begining with 'username'=> and remove them.

I began my regex, but I'm a little bit stuck :

This code selects any lines begining with username :

(?<='username'=>)

but I wondering how can I select the end of the line too and remove it ?

This is an example :

'username'=> 'CRPV',

I'm working with Visual Studio Code.

Thank you in advance for your help.

Jun
30
1 month ago
Activity icon

Replied to I Try To Get Some Data, But I Have All The Pages Code As Response (AJAX)

You're the best Jamal, thank you Friend.

Activity icon

Replied to I Try To Get Some Data, But I Have All The Pages Code As Response (AJAX)

I'm very tired and confused.... Thank you so much Jamal...

How can I put this post as resolve ?

Again, thank you.

Activity icon

Replied to I Try To Get Some Data, But I Have All The Pages Code As Response (AJAX)

Thank you jamalroger, yes indeed, I have this code now :

public function get_herbs()
    {
        $herbs = Herb::all();
        return $herbs;
        // return $herbs->toJson();
    }

But I get an empty array

[]

Maybe Have I to add some code about herb in the model ?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Herb extends Model
{
    use Notifiable;

    protected $fillable = ['name', 'sciname', 'user_id'];

    public function temporary()
    {
        return $this->hasOne(TemporaryData::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id');
    }

    public function herb_forms() {
        //DD herb_has_forms c'est le nom de la table pivot
        return $this->belongsToMany(HerbForm::class, 'herb_has_forms')->withTimestamps();
    }

    public function targets()
    {
        return $this->belongsToMany(Target::class, 'hinteractions')->withTimestamps();
    }

    public function hinteractions() 
    {
        return $this->hasMany(Hinteraction::class);
    }


    //Thierry Tester


}
Activity icon

Started a new Conversation I Try To Get Some Data, But I Have All The Pages Code As Response (AJAX)

Hello,

I'm trying to get data from a table to put them in a select list.

I have this JS code :

$.ajax
    ({
        type: 'GET',
        url: '../hinteractions/hdi',
        dataType: 'json',
        success: function(retour)
        {
            alert(retour);
            alert("dans succes");
        },
        error:function(retour)
        {
            alert('dans erreur');
        }
    });

This is the controller :

public function index()
    {
        $herbs = Herb::all();
        $json = json_encode($herbs);

        return view('interaction.index', compact('herbs', 'json'));
    }

I don't understand why I get as response the full page and not only my data ?

My response (only accepted if I put data : text) is something begining with this code :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

Do you have any idea how can I get only $herbs ?

Thank you for your help.

Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

Works greta. Thank you.

I used the bad controller.

Sorry and thank you again.

Jun
29
1 month ago
Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

For information, when I crypt the name and firstname like this, the result is that the name and firstname are not crypted :

$user->name = encrypt($request->name);
$user->firstname = encrypt($request->firstname);

This is the full code :

$user = new User;

        $user->user_id = Auth::user()->id;
        $user->name = encrypt($request->name);
        $user->firstname = encrypt($request->firstname);
        $user->team = $request->team;
        $user->tel1 = $request->tel1;
        $user->tel2 = $request->tel2;
        $user->email = $request->email;
        $user->email_verified_at = $request->email_verified_at;
        $user->password = $request->password;
        $user->remember_token = $request->remember_token;
        $user->role_id = $request->role_id;
        $user->save();
        Alert::success('Ok !', 'Nouveau user ajouté avec succès');

Thank you for your help

Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

The idea is to encrypt the name and firstname.

I have to decrypt it only once...

Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

Great reply, thank you very much.

Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

Thank you for your reply.

Do you have any advices to protect my database ?

Thank you again.

Jun
28
1 month ago
Activity icon

Started a new Conversation Encrypt And Decrypt Name And First Name ?

Hi everbody and thank you in advance for your help,

I'm developping for my job a Laravel site with MySQL database.

I would like to be safe in encrypting name and first name (in case my DB will be hacked).

Several questions :

1- Do you think it's important ? For GRPD for example... 2- Is this possible to do that ? Yes, encrypted, that's possible, decrypt, that's another thing...

Thank you in advance for your advices.

Activity icon

Replied to I Have To Put A / And My Colleague No... Very Strange

Thank you very much.

I think we have to check routes...

Anyway, I will come back here to give you the results of those tests.

Thank you again.

Jun
26
1 month ago
Activity icon

Started a new Conversation I Have To Put A / And My Colleague No... Very Strange

Hello everyone,

We have a very strange problem with this code:

            type: 'POST',
            url: 'admin / quickEdit',
            data: { 

We are a team of developers, when I test the site locally on my computer, I have to remove the character "/" from the URL:

url: 'admin / quickEdit',

on the other hand, my colleagues must put it ... so:

url: '/ admin / quickEdit',

If I don't put it, I have a 404 error.

I work under MAMP and my colleagues under craftsman serve.

Do you have any idea how to solve this problem please?

Thank you in advance.

David

Jun
01
2 months ago
Activity icon

Replied to Send An Email To Admin After Mail Verified.

Thank you mvdnbrk, great reply.

Activity icon

Started a new Conversation Send An Email To Admin After Mail Verified.

Hello,

I'm working with Laravel 7.11

I'm using the laravel's very mail.

When the mail is verified, I woud like to send an email to an admin with two links inside (accept/deny).

My questions :

1- Can I still use the Laravel's verify in this case ? (I red this post https://laracasts.com/discuss/channels/laravel/how-to-send-an-email-to-admin-after-verify-the-user and the dev does not use the laravel's verify)

2- Is this possible to send an Email to a user after have verified the mail ? if yes, do you have any idea please ?

Thank you in advance for your help.

May
31
2 months ago
Activity icon

Replied to [Laravel 7] Customize Verification Mail

Yes of course, but how ?

I have asked myself this question several times.

Thank you.

Activity icon

Replied to [Laravel 7] Customize Verification Mail

Great reply, thank you Michal.

Have a nice sunday.

David

Activity icon

Started a new Conversation [Laravel 7] Customize Verification Mail

Hi,

I would like to customize (add a logo, change text...) for the several mails sent by Laravel like for the email confirmation.

What's the best way to do it please ?

Thank you in advance for your help.

May
24
2 months ago
Activity icon

Replied to Reach A Value Of An Object

Thank you reply.

I work a verly long time to find a solution, but nothing until now...

I think, the best way is to use the query 2 with the query 1:

Query 1

$informations_plante = DB::table('herbs')
            ->select('herbs.name as hname', 'herbs.sciname', 'herbs.id as herbid','hinteractions.id as hinteractionid','hinteractions.note as hinteractionnote','hinteractions.force_id','targets.name as targetname', 'forces.name as force_name')
            ->leftJoin('hinteractions', 'herbs.id', '=', 'herb_id')
            ->leftJoin('forces', 'forces.id', '=', 'force_id')
            ->leftJoin('targets', 'targets.id', '=', 'hinteractions.target_id')->where('herbs.id', $id)
            //add here query 2
            ->get();

Query 2

    $hinteractions_has_effects = DB::table('hinteraction_has_effects')
                     ->select(DB::raw('effect_id, hinteraction_id'))
                     ->where('hinteraction_id', '=', 1)
                     ->get();

Have you any idea please ?

Thank you in advance.

May
23
2 months ago
Activity icon

Replied to Guidelines For Posting On Laracasts.com

Hi, thank you for your great job.

I'm not ablet to display a picture with html tages.

I tried for example : Img

It does not work, any idea please ?

Thank you again.

Activity icon

Replied to Reach A Value Of An Object

Hello Michal,

Thank you very much for your help, indeed, I have now right information.

But, now, this data is not display anymore :

<td>
						
						{{$hinteraction->force_name}}
					</td>

That's because I have two queries, one LEFT JOIN and antoher many to many :

First query :

public function details($id)
    {
        //DD je récupère les informations de la plante
        //DB::enableQueryLog();
        $informations_plante = DB::table('herbs')
            ->select('herbs.name as hname', 'herbs.sciname','hinteractions.*','targets.name as targetname', 'forces.name as force_name')
            ->leftJoin('hinteractions', 'herbs.id', '=', 'herb_id')
            ->leftJoin('forces', 'forces.id', '=', 'force_id')
            ->leftJoin('targets', 'targets.id', '=', 'hinteractions.target_id')->where('herbs.id', $id)
            ->get();

Second query :

            $hinteractions_has_effects = Hinteraction::with('effects')->get();

and moreover, the displayed result is identical for each plant, it looks like it does not take into account the plant id.

Do you have any idea please ?

Thank you in advance.

David

May
22
2 months ago
Activity icon

Replied to Reach A Value Of An Object

Hello,

Thank you for your reply.

I edit my reply, this is my new code :

@foreach ($hinteractions_has_effects as $hinteractions_has_effect)
							@foreach($hinteractions_has_effect->effects as $effect)
								{{$effect->name}}	
							@endforeach
						@endforeach

It displays information, but ALL information now...

inhibiteur inducteur inducteur inhibiteur inducteur substrat

Thank you for your help.

Activity icon

Started a new Conversation Reach A Value Of An Object

Hi everybody,

I have this object :

Part 1 of the object :

https://www.dropbox.com/s/p5v9j3hj0yrqy0q/Capture%20d%27%C3%A9cran%202020-05-22%2017.15.01.png?dl=0

Part 2 of the object :

https://www.dropbox.com/s/s544edbkjo34lc0/Capture%20d%27%C3%A9cran%202020-05-22%2017.15.13.png?dl=0

I would like to get the value inside de border (see link Part 2 of the object).

My code :

It's a many to many, I have 2 models :

Model Hinteraction :

public function effects() {
        //DD: une hinteraction peut avoir plusieurs effets et un effet peut se trouver dans plusieurs hinteractions 
        return $this->belongsToMany(Effect::class, 'hinteraction_has_effects'); 
    }

Model Effect :

class Effect extends Model
{
    //DD: une hinteraction peut avoir plusieurs effets et un effet peut se trouver dans plusieurs hinteractions
    public function hinteractions() 
{ 
        return $this->belongsToMany(Hinteraction::class, 'hinteraction_has_effects'); 
}
            $hinteractions_has_effects = Hinteraction::with('effects')->get();

I tried to make this :

@foreach ($hinteractions_has_effects as $effect)
	{{$effect->name}}	
@endforeach

But I don't have no name.

Thank you in advance for your help.

May
21
2 months ago
Activity icon

Replied to Multiple Left Join, Information Not Present In The Result.

I found the soluton :

I justed put alias because I had two times name in the result :

$plante = DB::table('herbs') ->select('herbs.name as hname, herbs.sciname','hinteractions.*','targets.name as targetname') ->leftJoin('hinteractions', 'herbs.id', '=', 'herb_id') ->leftJoin('targets', 'targets.id', '=', 'hinteractions.target_id')->where('herbs.id', $id) ->get();

Thank you for your help.

Activity icon

Replied to Multiple Left Join, Information Not Present In The Result.

Hi,

Thank you for your quick reply.

#11 name is from target table :

https://www.dropbox.com/s/x84ilwzaaobwvsd/Capture%20d%27%C3%A9cran%202020-05-21%2010.56.48.png?dl=0

I need the target name and the herb name also... not only the target name.

I would like to display the query, is this possible ?

Thank you again.

Activity icon

Started a new Conversation Multiple Left Join, Information Not Present In The Result.

Hello everybody and thank you in advance for your help.

I try to create a multiple Left Joint query like this :

$plante = DB::table('herbs') ->select('herbs.*','hinteractions.*','targets.*') ->leftJoin('hinteractions', 'herbs.id', '=', 'herb_id') ->leftJoin('targets', 'targets.id', '=', 'hinteractions.target_id')->where('herbs.id', $id) ->get();

I got this result :

https://www.dropbox.com/s/ncig98n6e00p24q/Capture%20d%27%C3%A9cran%202020-05-21%2011.01.29.png?dl=0

That's great, but I'm surprised that I don't get information about the herb like the name of the plante (Ail), the sciname...

Like you can see, herb_id = 6, I don't have any information...

This is the content of my herbs record, it does not appear in the SQL result :

https://www.dropbox.com/s/zquw1nlzvx55418/Capture%20d%27%C3%A9cran%202020-05-21%2010.46.55.png?dl=0

Thank you in advance for your help.

May
20
2 months ago
Activity icon

Started a new Conversation Redirection Quand La Session Se Termine

Hi everybody,

When my session end, I have this message :

https://www.dropbox.com/s/6gtk3156p18sosr/Capture%20d%27%C3%A9cran%202020-05-20%2009.06.08.png?dl=0

I would like to add a redirection when the session is end.

Do you know where can I change that redirection ?

Thank you in advance.

May
19
2 months ago
Activity icon

Replied to Unable To Comeback To My Page (route)

Hi Michal,

Thank you, once again you resolved my problem.

Have a nice evening.

David

Activity icon

Started a new Conversation Unable To Comeback To My Page (route)

Hi,

I am in this page public/herbs/details_plante/8

When I click on my menu, I would like to go back to public/herb but I have this URL :

public/herbs/details_plante/herb

I don't understand why it replaces 8 by herb rather than go back to herb ?

This is my routes code :

[code]Route::get('herb/details_plante/{id}','[email protected]')->name('herbs.details');[/code]

[code]Route::get('/herb','[email protected]')->name('herbs.index');[/code]

Thank you in advance for your help.

May
17
2 months ago
Activity icon

Replied to Display Records From 2 Tables Through A Pivot Table

Hi Michal,

I try to use Laravel with all conventions... and I'm a little bit worry about what you said on yesterday :

But be careful, your pivot table herbs_have_forms is not as default laravel convention.

How have I to do to be OK with Laravel ?

Thank you for your help.

David

May
16
2 months ago
Activity icon

Replied to Display Records From 2 Tables Through A Pivot Table

Thank you so much Michal for all you are doing for everybody here...

I will read again your reply in a few hours and I will to understand.

All is working great tahnks to you.

Thank you again.

DAvid

Activity icon

Replied to Display Records From 2 Tables Through A Pivot Table

Great reply Michal, THANK YOU very much.

With this code

$herb = Herb::with('herb_forms')->get();

dd($herb); // this will be your collection of forms*/

I have this collection :

#items: array:10 [▼ 0 => App\Herb {#522 ▼ #connection: "mysql" #table: "herbs" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:6 [▼ "id" => 1 "name" => "Echinacées" "sciname" => "Echinacea sp." "created_at" => "2020-05-16 20:26:48" "updated_at" => "2020-05-16 20:26:48" "user_id" => 1 ] #original: array:6 [▶] #changes: [] #casts: [] #classCastCache: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [▼ "herb_forms" => Illuminate\Database\Eloquent\Collection {#538 ▼ #items: array:1 [▼ 0 => App\HerbForm {#573 ▼ #connection: "mysql" #table: "herb_forms" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:4 [▼ "id" => 1 "name" => "Caps" "created_at" => "2020-05-16 20:26:48" "updated_at" => "2020-05-16 20:26:48" ] #original: array:6 [▶] #changes: [] #casts: [] #classCastCache: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [▶] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] } ] } ] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] }

If I try to display herb_forms with this code :

dd($herb->forms); // this will be your collection of forms*/

I have this error :

Property [herb_forms] does not exist on this collection instance.

How can I please reach the herb_forms value ?

Thank you again for all.

David

Activity icon

Replied to Display Records From 2 Tables Through A Pivot Table

Hello Michal,

Thank you for your reply.

I tried your code, I have this message :

Call to undefined relationship [forms] on model [App\Herb].

My herb model contains :

public function herb_forms() { return $this->belongsToMany(HerbForm::class); }

and my herb_forms contains :

public function herbs() { return $this->belongsToMany(Herb::class); } my model herbs_has_form is empty, like this :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class HerbHasForm extends Model { // }

Once I will understand for this one, I will understand for all others.

Thank you again for your help.

David

Activity icon

Started a new Conversation Display Records From 2 Tables Through A Pivot Table

Hello,

I have two tables :

Herbs :

1 herb1 2 herb2

herb_forms

1 Tea 2 Caps

One herb can have several forms and one forms have several herbs, I created a pivot table :

herbs_have_forms

1 - 1 1- 2 2- 1

I would like to know how can I display the name of herbs and his form please ?

I did all, seed, model, controller... but I don't know how can I create a many to many query ?

Thank you in advance for your help.

May
03
3 months ago
Activity icon

Started a new Conversation Laravel 7 Data-table Yajra Not Responsive

Hello everybody,

I'm using Yajra datatable from a weblesson tutorial.

All is working great, but the data-table is NOT responsive.

I included this code :

[code] $('#user_table').DataTable({ responsive: true,[/code]

Like you can on this photo, my table is not responsive :

I searched before posting, but it seems that nobody has this problem ?

Here is my code : [code] How to Delete or Remove Data From Mysql in Laravel 6 using Ajax

    <nav class="navbar navbar-default">
        <div class="container-fluid">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header" >
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Accueil</a>
          </div>
      
          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Clients <span class="sr-only">(current)</span></a></li>
              <li><a href="#">Abonnements</a></li>
              <li><a href="#">Paiements</a></li>
              <li><a href="#">Articles</a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
                  <li role="separator" class="divider"></li>
                  <li><a href="#">Separated link</a></li>
                  <li role="separator" class="divider"></li>
                  <li><a href="#">One more separated link</a></li>
                </ul>
              </li>
            </ul>
            
            <ul class="nav navbar-nav navbar-right">
              <li><a href="#">Déconnexion</a></li>
              
            </ul>
          </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
      </nav>
    


  <div class="container">    
     <br />
     
     

     
     

     <br />
     <h3 align="center">Gestion des membres de la salle de sport NAJA</h3>
     <br />
     
     
     
     <div align="right">
      <button type="button" name="create_record" id="create_record" class="btn btn-success btn-sm">Ajouter un client</button>
     </div>
     <br />
   <div class="table-responsive">
    <table id="user_table" class="table table-bordered table-striped">
     <thead>
      <tr>
       <th width="35%">First Name</th>
                <th width="35%">Last Name</th>
                <th width="30%">Action</th>
      </tr>
     </thead>
    </table>
   </div>
   <br />
   <br />
  </div>
 </body>
</html>

<div id="formModal" class="modal fade" role="dialog">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Ajouter un nouveau client</h4>
        </div>
        <div class="modal-body">
         <span id="form_result"></span>
         <form method="post" id="sample_form" class="form-horizontal">
          @csrf
          <div class="form-group">
            <label class="control-label col-md-4" >First Name : </label>
            <div class="col-md-8">
             <input type="text" name="first_name" id="first_name" class="form-control" />
            </div>
           </div>
           <div class="form-group">
            <label class="control-label col-md-4">Last Name : </label>
            <div class="col-md-8">
             <input type="text" name="last_name" id="last_name" class="form-control" />
            </div>
           </div>
                <br />
                <div class="form-group" align="center">
                 <input type="hidden" name="action" id="action" value="Add" />
                 <input type="hidden" name="hidden_id" id="hidden_id" />
                 <input type="submit" name="action_button" id="action_button" class="btn btn-warning" value="Add" />
                </div>
         </form>
        </div>
     </div>
    </div>
</div>

<div id="confirmModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h2 class="modal-title">Confirmation</h2>
            </div>
            <div class="modal-body">
                <h4 align="center" style="margin:0;">Voulez-vous vraiment supprimer ce client ?</h4>
            </div>
            <div class="modal-footer">
             <button type="button" name="ok_button" id="ok_button" class="btn btn-danger">OK</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>


<script>
$(document).ready(function(){

 $('#user_table').DataTable({
  responsive: true,
  processing: true,
  serverSide: true,
  
  ajax: {
   url: "{{ route('sample.index') }}",
  },
  columns: [
   {
    data: 'first_name',
    name: 'first_name'
   },
   {
    data: 'last_name',
    name: 'last_name'
   },
   {
    data: 'action',
    name: 'action',
    orderable: false
   }
  ]
 });

 $('#create_record').click(function()
 {
  $('.modal-title').text('Ajouter un nouveau client');
  $('#action_button').val('Add');
  $('#action').val('Add');
  $('#form_result').html('');

  $('#formModal').modal('show');
 });

 $('#sample_form').on('submit', function(event){
  event.preventDefault();
  var action_url = '';

  if($('#action').val() == 'Add')
  {
   action_url = "{{ route('sample.store') }}";
  }

  if($('#action').val() == 'Edit')
  {
   action_url = "{{ route('sample.update') }}";
  }

  $.ajax({
   url: action_url,
   method:"POST",
   data:$(this).serialize(),
   dataType:"json",
   success:function(data)
   {
    var html = '';
    if(data.errors)
    {
     html = '<div class="alert alert-danger">';
     for(var count = 0; count < data.errors.length; count++)
     {
      html += '<p>' + data.errors[count] + '</p>';
     }
     html += '</div>';
    }
    if(data.success)
    {
     html = '<div class="alert alert-success">' + data.success + '</div>';
     $('#sample_form')[0].reset();
     $('#user_table').DataTable().ajax.reload();
    }
    $('#form_result').html(html);
   }
  });
 });

 $(document).on('click', '.edit', function(){
  var id = $(this).attr('id');
  $('#form_result').html('');
  $.ajax({
   url :"sample/"+id+"/edit",
   dataType:"json",
   success:function(data)
   {
    $('#first_name').val(data.result.first_name);
    $('#last_name').val(data.result.last_name);
    $('#hidden_id').val(id);
    $('.modal-title').text('Edit Record');
    $('#action_button').val('Edit');
    $('#action').val('Edit');
    $('#formModal').modal('show');
   }
  })
 });

 var user_id;

 $(document).on('click', '.delete', function(){
  user_id = $(this).attr('id');
  $('#confirmModal').modal('show');
 });

 $('#ok_button').click(function(){
  $.ajax({
   url:"sample/destroy/"+user_id,
   beforeSend:function(){
    $('#ok_button').text('Deleting...');
   },
   success:function(data)
   {
    setTimeout(function(){
     $('#confirmModal').modal('hide');
     $('#user_table').DataTable().ajax.reload();
     alert('Data Deleted');
    }, 2000);
   }
  })
 });

});
</script>

[/code]

Thank you.

Apr
13
3 months ago
Activity icon

Replied to Difference Between Increments, And BigIncrements?

Hi, why have I this as default ? :

$table->id();

Is this the same as $table->bigIncrements('id'); ?

Thank you for your help.

Apr
05
4 months ago
Activity icon

Replied to A Doubt About The Code And Relationship Between Two Tables

Hi Boby,

Thank you for your quick reply.

I can give any name to those functions ?

public function drug_familie() and to public function drugs()

or Laravel has to have the name of the table in singular ?

Thank you again.

PS: I will try and I will let you know.

Apr
04
4 months ago
Activity icon

Started a new Conversation A Doubt About The Code And Relationship Between Two Tables

Hello,

I have two tables :

1- drug (id, name) 2 drug_families (id, name)

One drug has ONE drug_family but a drug_family can have several drugs.

I did this code on my migration :

public function up() { Schema::create('drugs', function (Blueprint $table) { $table->id(); $table->string('name',45); $table->datetime('validated'); $table->timestamps();

        //création d'une clé étrangère, un médicament appartient à une seule famille, une famille
        //peut avoir plusieurs médicaments.
        $table->unsignedBigInteger('drug_family_id');
        $table->foreign('drug_family_id')
        ->references('id')
        ->on('drug_families')
        ->onDelete('cascade')
        ->onUpdate('cascade');
    });
}

I have a doubt about the models :

my drug model :

namespace App;

use Illuminate\Database\Eloquent\Model;

class Drug extends Model { public function drug_familie() { return $this->belongsTo(DrugFamilie::class); } } and my drug_familie model :

namespace App;

use Illuminate\Database\Eloquent\Model;

class DrugFamilie extends Model { public function drugs() { return $this->hasMany(Drug::class); } } Do you think this code is correct ?

Thank you in advance for your help.

Apr
01
4 months ago
Activity icon

Replied to How To Do Insertions Correctly In Laravel 6 ?

Hello, I will be very interesed by a reply too... Thank you in advance.