Laravel 5 tutorial, How To Insert Data in Database




Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling.

Original source


38 responses to “Laravel 5 tutorial, How To Insert Data in Database”

  1. this helping me a lot , today i try to inset the data to the mssql database : i use $product = new product;
    $product->pro_name = $request->pro_name;
    $product->pro_code = $request->pro_code;
    $product->pro_price = $request->pro_price;
    $product->pro_info = $request->pro_info;
    $product->pro_img = $filename;
    $product->spl_price = $request->spl_price;
    $product->save(); then Error message keep saying in MSsql server invalid object name [products] , so i try u formal ,and it works , thank for you video tutorial.

  2. this tutorial controller page do not import for database library.
    you can add import your code in controller page for input database :

    namespace AppHttpControllers;
    use IlluminateHttpRequest;
    use AppHttpRequests;
    use IlluminateSupportFacadesDB;

    I give example of contolller page

    <?php

    namespace AppHttpControllers;

    use IlluminateHttpRequest;

    use AppHttpRequests;

    use IlluminateSupportFacadesDB;

    class RegController extends Controller
    {
    //

    public function reg(){
    return view('Registration');
    }

    public function insert(Request $req){

    $student_id = $req->input('student_id');
    $course_code = $req->input('course_code');
    $course_title = $req->input('course_title');
    $course_credit = $req->input('course_credit');

    $data = array('student_id'=> $student_id ,'course_code'=>$course_code,'course_title'=>$course_title,'course_credit'=>$course_credit );

    DB::table('course')->insert($data);

    return back();

    }
    }

  3. how to fixed it.
    QueryException in Connection.php line 647:
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'country_code' cannot be null (SQL: insert into `location` (`country_code`, `country`, `city_region`, `zip`) values (, , , ))

  4. Can you do a tutorial on a 'favourite' system, so maybe there's some data (for example a charity), and the current user wants to add that charity to their favourites list. Their favourites list could be displayed on their profile page?

  5. Web.php

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

    Route::post('/insert', 'Controller@insert');

    ——————————————————-
    Controller.php

    <?php

    namespace AppHttpControllers;

    use IlluminateFoundationBusDispatchesJobs;
    use IlluminateRoutingController as BaseController;
    use IlluminateFoundationValidationValidatesRequests;
    use IlluminateFoundationAuthAccessAuthorizesRequests;

    class Controller extends BaseController
    {
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    function insert(Request $req)
    {
    $email = $req -> input('email');
    $mesaj = $req -> input('mesaj');

    $data = array('email'=>$email, "mesaj"=>$mesaj);

    DB::table('mesajlar')->insert($data);

    echo "Mesaj Gönderildi";
    }
    }
    ————————————–
    insertForm.blade.php

    <!DOCTYPE html>
    <html>
    <head>
    <title>Insert Form</title>
    </head>
    <body>
    <center>

    <form action="/insert" method="post">
    <table>
    <tr>
    {{ csrf_field() }}
    <td>E-Mail : </td>
    <td><input type="text" name="email"></td>
    </tr>
    <tr>
    <td>Mesaj : </td>
    <td><textarea rows="4" cols="20" name="mesaj"></textarea></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" value="Gönder"></td>
    </tr>
    </table>
    </form>

    </center>
    </body>
    </html>

    Everything looking good but i have a problem The requested URL /insert was not found on this server. It is not see /insert HELP ME PLS

Leave a Reply