Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

henrique_f

henrique_f

Member Since 4 Weeks Ago

Experience Points
3,070
Total
Experience

1,930 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
29
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
3,070 XP
Nov
03
3 weeks ago
Activity icon

Replied to Store On Database With Axios

@automica I had tried this before but also did not solve it.

Activity icon

Replied to Store On Database With Axios

@pom, when I do this change the response message surprisingly is:

"The GET method is not supported for this route. Supported methods: POST."

Activity icon

Started a new Conversation Store On Database With Axios

Hello! I've been searching and trying different methods, especially the Serie Learn Vue 2: Step By Step.

I successfully get the front end of my menu and it also successfully bind the input to the object fields.

Some input fields are just displayed on the frontend because I am just testing to add the rest afterward.

Even though I haven't been able to bind this object to the store() function, since the response returns:

"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Ref' cannot be null(SQL: insert into 'cmr' ('Ref' ....)"

So I think my error is either on the script part of CreateForm.vue or on my Controller. Any suggestions, recommendations, or a slap on the wrist are welcome.

CreateForm.vue

<template>
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-8">
        <div class="card">
          <div id="app">

            <span v-for="e in errors">{{ e }}</span>

            <form method="post" action="/create" @submit.prevent="onSubmit" >
              <section v-if="step == 1">
                <h3>New ECMR</h3>

                <label for="">Add to existing</label>
                <input type="radio" name="method" value="Add to existing">

                <label for="">New Transport</label>
                <input type="radio" name="method" value="New Transport">

                <div class="">
                  <label for="">Reference*</label>
                  <input required type="text" v-model="fields.Ref">
                </div>

                <div class="">
                  <label for="CMRtype">Type of CMR*</label>
                  <select required class="" name="CMRtype" v-model="fields.CMRtype">
                    <option value="international_CMR">International CMR</option>
                    <option value="consigment_note">Consigment Note</option>
                  </select>
                </div>

                <p>(*) Mandatory</p>

              </section>

                <section v-if="step == 2">
                  <h3>Consignor</h3>
                  <div class="">
                    <label for="">Order Number</label>
                    <input type="text" name="Order" v-model="fields.Order">
                  </div>

                  <div class="">
                    <label for="">Consignor*</label>
                    <input required type="text" name="Consignor" v-model="fields.Consignor">
                  </div>

                  <div class="">
                    <label for="">Different Adresss than the consignor</label>
                    <input type="checkbox" name="DiffAdressConsignor" value="yes" v-model="fields.DiffAdressConsignor">
                  </div>

                  <div class="">
                    <label for="">Date*</label>
                    <input required type="date" name="DateTakingOver" v-model="fields.DateTakingOver">
                    <label for="">at</label>
                    <input required type="time" name="TimeTakingOver" v-model="fields.TimeTakingOver">
                  </div>

                  <p>(*) Mandatory</p>
                </section>

                <section v-if="step == 3">
                  <h3>Consignee</h3>
                  <div class="">
                    <label required for="">Consignee*</label>
                    <input type="text" name="Consignee" v-model="fields.Consignee">
                  </div>

                  <div class="">
                    <label for="">Different Adresss than the consignee</label>
                    <input type="checkbox" name="DiffAdressConsignee" value="yes">
                  </div>

                  <div class="">
                    <label for="">Agreed date of delivery</label>
                    <input type="date" name="DateDelivery" v-model="fields.DateDelivery">
                    <label for="">at</label>
                    <input type="time" name="TimeDelivery" v-model="fields.TimeDelivery">
                  </div>

                  <p>(*) Mandatory</p>
                </section>

                <section v-if="step == 4">
                  <h3>Carrier</h3>
                  <div class="">
                    <label for="">Carrier*</label>
                    <input required type="text" name="Carrier" v-model="fields.Carrier">
                  </div>

                  <div class="">
                    <label for="">Driver*</label>
                    <input required type="text" name="Driver1" v-model="fields.Driver1">
                    <label for="">Driver 2</label>
                    <input type="text" name="Driver2">
                  </div>

                  <div class="">
                    <label for="">Truck*</label>
                    <input required type="text" name="Truck" v-model="fields.Truck">

                    <label for="">Trailer</label>
                    <input type="text" name="Trailer" v-model="fields.Trailer"><br>

                    <label for="">Trailer 2</label>
                    <input type="text" name="Trailer2" v-model="fields.Trailer2">
                  </div>

                </section>

                <section v-if="step == 5">
                  <h3>Conditions</h3>
                </section>

                <button
                v-if="step != 1"
                @click.prevent="prevStep" type="button" name="button">Previous Step</button>

                <button
                v-if="step != totalsteps"
                @click.prevent="nextStep" type="button" name="button">Next Step</button>

                <button
                v-if="step == totalsteps"
                type="submit" name="button">Submit</button>

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

</template>

<script>
  /*  */
      export default {
        data() {
          return {
            fields: {},
            errors:{},
            step: 1,
            totalsteps: 5
          }
        },

        methods: {

          nextStep()
          {
            if(this.step == 1){
              if(!this.fields.Ref){
                this.errors = 'Please fill all the fields';
                return false;
              }
            }
            this.step++;
          },

          prevStep()
          {
            this.step--;
          },

          onSubmit() {
            this.errors = {};
            axios.get('/store', this.fields).then(response => {
              alert('Message sent!');
            }).catch(error => {
              if (error.response.status === 422) {
                this.errors = error.response.data.errors || {};
              }
            });
        }

      }
    }

</script>

CreateCMRController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\eCMR;
use DB;

class CreateCMRController extends Controller
{
    //
    public function view_records() {
       $cmr = DB::select('SELECT * FROM cmr');

       return view ('operations', compact('cmr'));

     }

    public function store()
    {
      $this ->validate(request(), [
        'Ref',
        'CMRtype',
        'Order',
        'Consignor',
        'DateTakingOver',
        'TimeTakingOver',
        'Consignee',
        'DateDelivery',
        'TimeDelivery',
        'Carrier',
        'Driver1',
        'Driver2',
        'Truck',
        'Trailer',
        'Trailer2'
      ]);

      eCMR::create([
        'Ref' => request('Ref'),
        'CMRtype' => request('CMRtype'),
        'Order' => request('Order'),
        'Consignor' => request('Consignor'),
        'DateTakingOver' => request('DateTakingOver'),
        'TimeTakingOver' => request('TimeTakingOver'),
        'Consignee'  => request('Consignee'),
        'DateDelivery' => request('DateDelivery'),
        'TimeDelivery' => request('TimeDelivery'),
        'Carrier' => request('Carrier'),
        'Driver1' => request('Driver1'),
        'Driver2' => request('Driver2'),
        'Truck' => request('Truck'),
        'Trailer' => request('Trailer'),
        'Trailer2' => request('Trailer2'),
      ]);

      return response()->json(null, 200);
    }

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\CreateCMRController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]')->name('front');

Route::get('home', '[email protected]');

Route::get('admin', '[email protected]');

Route::get('company_info', '[email protected]_info');

Route::get('operations', '[email protected]');

Route::get('operations', '[email protected]_records');

Route::get('operations/new_ecmr', '[email protected]_ecmr');

Route::get('/store', '[email protected]');

Route::get('search', '[email protected]');

Auth::routes();

my model eCMR.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class eCMR extends Model
{
    use HasFactory;
    protected $table = 'cmr';

    protected $fillable = [
        'Ref',
        'CMRtype',
        'Order',
        'Consignor',
        'DateTakingOver',
        'TimeTakingOver',
        'Consignee',
        'DateDelivery',
        'TimeDelivery',
        'Carrier',
        'Driver1',
        'Driver2',
        'Truck',
        'Trailer',
        'Trailer2',
    ];
}
Oct
28
4 weeks ago
Activity icon

Replied to Undefined Variable: Users

@michaloravec I am learning only by the documentation and it is very helpful, but sometimes I misinterpreted and get confused with some concepts.

Activity icon

Replied to Undefined Variable: Users

@snapey you were right! Thanks for your answer

I misunderstood the controller concept. After replacing the first argument on the get function for the view where I would like to display the user information I successfully got the results from the database.

Route::get('operations', '[email protected]_records');

Newbie problems hahaha thanks for everyone who tried to helped me.

Activity icon

Replied to Undefined Variable: Users

@laracoft Yes.

web2.com/operations

Activity icon

Replied to Undefined Variable: Users

hahaha

How do you mean by /view_records?

Activity icon

Replied to Undefined Variable: Users

That is the error I get

ErrorException
Undefined variable: users (View: /var/www/web2/resources/views/operations.blade.php) 

on the operations.blade.php this is the row highlighted

@foreach ($users as $row)
Activity icon

Started a new Conversation Undefined Variable: Users

I have watched different tutorials to retrieve data from a DB and I think I understood the mechanism.

I manage to insert data into the DB but I am struggling to view the contents.

I omit the create function on the controller since it is working perfectly.

My web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\CreateCMRController;

Route::get('/create', '[email protected]');

Route::get('view_records', '[email protected]_records');

Auth::routes();

Operations.blade.php

@extends('layouts.master')
@section('title', 'Operations')
@section('content')

<div class="container">
    <div class="row justify-content-center">
      <div class="col-md-8">
          <div class="card">
            <table>
              @foreach ($users as $row)
              <tr>
                <td>{{ $row->name }}</td>
              </tr>
              @endforeach
            </table>
          </div>
      </div>
        <div class="col-md-8">
            <div class="card">
              <a style="margin-left: 10px;" href="operations/new_ecmr"> New  </a>
            </div>
        </div>
    </div>
</div>
@endsection

CreateCMRController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\eCMR;
use DB;

class CreateCMRController extends Controller
{
   
    public function view_records() {
       $users = DB::select('SELECT * FROM users');

       return view ('operations', ['users'=>$users] );
     }
}