lundi 29 janvier 2018

Automatically set value in database during data insertion?

My website is built in Laravel and if I add an item to the website, the URL is automatically set in a certain format. I like the format. What I am wondering is how can I edit the INSERT code so that the URL is set when I insert multiple rows of data into the database via file import (I am using a file import script)? The URL is not in the file itself. Everytime a row is inserted into the database, the URL should automatically be set for that particular item.

The Add Item form on the website uses the following code to automatically set the URL:

            $find=array(",","."," ");
            $replace=array("","","-");
            $titleurl = str_replace($find,$replace, $sname);
              $url='schools/'.strtolower($titleurl);
              $check=schools::where('url', '=', $url)->first();
              if(count($check)>0){
                   return redirect()->back()
                ->with('message', 'Looks like there is a similar school. please review post');
              }

Example of what my INSERT code looks like:

      $query = "INSERT INTO schools (
            id,
            name
       ) VALUES (
        '$id',
        '$name'
         )";



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

Aucun commentaire:

Enregistrer un commentaire