samedi 1 avril 2017

Laravel 5 Migration Error Column not found: 1054 Unknown column 'name_with_initials' in 'field list'

I`m developing a large form for a web site.after setting everything i tried to enter inputs and it getting error like this enter image description here

Here is the model userregistration

   class userregistration extends Model
{

    protected $table = "userregistration";
   protected $fillable = ['id','full_name','name_with_initials','nic_no','date_of_birth','age','sex','marital_status','Permanent_address','temporary_address','home_tel','mobile_tel','gce_ol_year','gce_ol_results','gce_al_year','gce_al_results','institute','qualification','batch','organization','completed_training','trainee_year','person_name','person_address','contact_number','relationship','start_date','end_date','training_type','bank_name','branch_name','account_no'];
}

Here is the controller store function

 public function store(Request $request)
{
    $item = new userregistration;
     // $item ->id = Auth::user() ->id;
    $item ->full_name = $request ->full_name; 
    $item ->name_with_initials = $request ->name_with_initials;
    $item ->nic_no = $request ->nic_no;
    $item ->date_of_birth = $request ->date_of_birth;
    $item ->age = $request ->age; 
    $item ->sex = $request ->sex;
    $item ->marital_status = $request ->marital_status;
    $item ->Permanent_address = $request ->Permanent_address;
    $item ->temporary_address = $request ->temporary_address; 
    $item ->home_tel = $request ->home_tel;
    $item ->mobile_tel = $request ->mobile_tel;
    $item ->gce_ol_year = $request ->gce_ol_year;
    $item ->gce_ol_results = $request ->gce_ol_results; 
    $item ->gce_al_year = $request ->gce_al_year;
    $item ->gce_al_results = $request ->gce_al_results;
    $item ->institute = $request ->institute;
    $item ->qualification = $request ->qualification; 
    $item ->batch = $request ->batch;
    $item ->organization = $request ->organization;
    $item ->completed_training = $request ->completed_training;
    $item ->trainee_year = $request ->trainee_year; 
    $item ->person_name = $request ->person_name;
    $item ->person_address = $request ->person_address;
    $item ->contact_number = $request ->contact_number;
    $item ->relationship = $request ->relationship; 
    $item ->start_date = $request ->start_date;
    $item ->end_date = $request ->end_date;
    $item ->training_type = $request ->training_type;
    $item ->bank_name = $request ->bank_name; 
    $item ->branch_name = $request ->branch_name;
    $item ->account_no = $request ->account_no;


    $item ->save();

         userregistration::create($request->all());
            return redirect()->route('/registration')
                    ->with('success','Item created successfully');   


 }

Here is the form i created

    <div class="form-group">

        <label>Full Name</label>
        <input type="hidden" value="" name="_token" />
        <input type="text" name="full_name" class="form-control" value="">
        </div>

        <div class="form-group">

        <label>Name with initials</label>
        <input type="text" name="name_with_initials"class="form-control" value="">
        </div>

        <div class="form-group">

        <label>National ID Number</label>
        <input type="text" name="nic_no"class="form-control" value="">
        </div>

        <div class="form-group">
        <label>Date Of Birth</label>
        <input class="form-control" name="date_of_birth" type="date" value="2011-08-19" id="example-date-input">
        </div>

        <div class="form-group">
         <label>Age</label>
        <input type="text" name="age"class="form-control" value="">
        </div>

        <div class="form-group">
         <label>Sex</label>
       <label class="radio-inline"><input type="radio" name="sex" value="male">Male</label>
        <label class="radio-inline"><input type="radio" name="sex" value="female">Female</label>
        </div>

    <div class="form-group">
    <label>marital Status</label>
        <label class="radio-inline"><input type="radio" name="marital_status" value="single">Single</label>
        <label class="radio-inline"><input type="radio" name="marital_status" value="married">Married</label>
        </div>

         <div class="form-group">
        <label>Permanent Address</label>
        <input type="text" name="Permanent_address"class="form-control" value="">
        </div>

         <div class="form-group">
        <label>Temporary Address</label>
        <input type="text" name="temporary_address"class="form-control" value="">
        </div>

         <div class="form-group">
        <label>Home Tel:</label>
        <input type="text" name="home_tel"class="form-control" value="">
        </div>

         <div class="form-group">
        <label>Mobile Tel:</label>
        <input type="text" name="mobile_tel"class="form-control" value="">
        </div>

        <label>EDUCATIONAL QUALIFICATIONS</label>

        &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;

  <div class="form-group">
        <label>GCE(O/L) Year:</label>
    <input class="form-control" name="gce_ol_year" type="month" value="2011-08" id="example-month-input">
  </div>

   <div class="form-group">
        <label>GCE(O/L) Results</label>
        <input type="text" name="gce_ol_results"class="form-control" value="">
        </div>


  <div class="form-group">
        <label>GCE(A/L) Year:</label>
    <input class="form-control" name="gce_al_year" type="month" value="2011-08" id="example-month-input">
  </div>

   <div class="form-group">
        <label>GCE(A/L) Results</label>
        <input type="text" name="gce_al_results" class="form-control" value="">
        </div>


<label>PROFESSIONAL QUALIFICATION</label>

<div class="form-group">
        <label>Institute</label>
        <input type="text" name="institute" class="form-control" value="">
        </div>

         <div class="form-group">
         <label>Qualification on</label>
       <label class="radio-inline"><input type="radio" name="qualification" value="bsc">BSc</label>
        <label class="radio-inline"><input type="radio" name="qualification" value="beng">BEng</label>
         <label class="radio-inline"><input type="radio" name="qualification" value="diploma">Diploma</label>
          <label class="radio-inline"><input type="radio" name="qualification" value="certificate">Certificate</label>
        </div>

        <div class="form-group">
        <label>Batch</label>
        <input type="text" name="batch" class="form-control" value="">
        </div>


<label>TRAINEE HISTORY</label>

<div class="form-group">
        <label>Organization</label>
        <input type="text" name="organization"class="form-control" value="">
        </div>

        <div class="form-group">
        <label>Completed Training</label>
        <input type="text" name="completed_training"class="form-control" value="">
        </div>

         <div class="form-group">
        <label>Year:</label>
    <input class="form-control" name="trainee_year" type="month" value="2011-08" id="example-month-input">
  </div>

  <label>PERSON TO CONTACT IN CASE OF EMERGENCY</label>

<div class="form-group">
        <label>Name</label>
        <input type="text" name="person_name"class="form-control" value="">
        </div>

        <div class="form-group">
        <label>Address</label>
        <input type="text" name="person_address"class="form-control" value="">
        </div>

        <div class="form-group">
        <label>Contact Number</label>
        <input type="text" name="contact_number"class="form-control" value="">
        </div>

        <div class="form-group">
        <label>Relationship to you</label>
        <input type="text" name="relationship"class="form-control" value="">
        </div>

<label>TRAINING PERIOD</label>

<div class="form-group">
        <label>Starting Date:</label>
    <input class="form-control" name="start_date" type="date" value="2011-08-19" id="example-date-input">
  </div>

  <div class="form-group">
        <label>End Date:</label>
    <input class="form-control" name="end_date" type="date" value="2011-08-19" id="example-date-input">
  </div>

  <div class="form-group">
    <label>Training Type</label>
        <label class="radio-inline"><input type="radio" name="training_type" value="general training">General Training</label>
        <label class="radio-inline"><input type="radio" name="training_type" value="on job training" >On Job Training</label>
        </div>

        <label>Bank Details</label>

<div class="form-group">
<label>Bank Name</label>
        <input type="text" name="bank_name" class="form-control" value="">
        </div>

<div class="form-group">
<label>Branch Name</label>
        <input type="text" name="branch_name" class="form-control" value="">
        </div>
<div class="form-group">
<label>Account No</label>
        <input type="text" name="account_no" class="form-control" value="">
        </div>



         <input type="submit" class="btn btn-success pull-right">


      </form>

            </div>

Can anyone help me to get solve this? Thank you.



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

Multiple database connection with same table manes laravel

I have two database having tables with same name. I am using laravel to connect through this.

Note : I am able to make multiple connections but I am unable to access tables having same name.

Example

Database 1 :

Table: ads

Database 2

Table: ads

How can I make database connection / model for these two different tables having same name , which are in two different databases.



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

Laravel 5.4 Error when create user

Hi i got problem when i create user. I got this error: FatalThrowableError in SessionGuard.php line 407: Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given, called in /home/mariusz/Pulpit/www/szpital/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 35

User is created anyway but this error is so anoying and i dont know how fix it. I use laravel auth and i little edit register controller becouse i need add role for user and now my controller looks like that.

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Role;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'lastname' => 'required|max:255',
            'phonenumber' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    }


    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * 
     */

     public function create(array $data)
    {
        $user = new User();
        $user->name = $data['name'];
        $user->lastname = $data['lastname'];
        $user->phonenumber = $data['phonenumber'];
        $user->email = $data['email'];
        $user->password = bcrypt($data['password']);
        $user->save();
        $user->roles()->attach(Role::where('name', 'User')->first());
        Auth::login($user);
        
        
    }
}
I dont know mybe i shouldnt edit it. I want explain when i got this error: 1.I go to page create acc. 2.I write name etc. 3.When i click create i got error 4. Next when i refresh page user is created,login and redirect to home page.

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

Datatable showing html in last column using laravel yajra

Please see html is showing when im showing datatable by using laravel 5.4 and yajra. i have tried render function and html decode in java script but not successful

Laravel 5.4 yajra

Controller

$contacts = DB::table('contacts')->select('id','Name','email','status');

        return Datatables::of($contacts)
            ->addColumn('action', function($row) {
                $_url = url('/showUpdateContact/' . $row->id);
                $link = "<a href=\"$_url\" data-original-title=\"Edit\">Edit</a>";

                $_url = url('/deleteContact/' .$row->id);
                $link .= "<a  title=\"Delete Contact\" data-original-title=\"Delete\" href=\"javascript:deleteItem('$_url')\">Delete</a>";

                return ($link);
            })
            ->removeColumn('id')
            ->make();


**View**
<script type="text/javascript">
    jQuery(document).ready(function() {

            var DTable = jQuery('#contactsTable').DataTable({
                "processing": false,
                "serverSide": true,
                "pageLength": 10,
                "bPaginate": true,
                "ordering": false,
                "bLengthChange": true,
                "bFilter": true,
                "bInfo": true,
                "ajax": {
                    "url": "",
                    "cache": false,
                    "Content-Type": "text/html",
                    "data": function ( d ) {
                        //d.cus_filter_on = $('#filter_on').val();
                    },
                    "complete": function() {
                        //Remove select2 effects from page length dropdown
                        //jQuery("select[name='contactsTable_length']").select2('destroy');
                        //jQuery('.loading').css('display','none');
                    },
                },
                "columnDefs": [
                    { "searchable": false, "targets": 0,
                        render: function ( data, type, row, meta ) {
                            console.log(data);
                            console.log(type);
                            console.log(row);
                            console.log(meta);
                            console.log('------');
                            return $('<div/>').html(data).text();
                        }
            }
                ],
            }); //DataTable ends
        }); //ready ends

</script>

I have also tried render function not luck



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

Can we store value of @yield in a variable

I have a simple question can we store the value that will be yielded in a variable.

for instance an example

$var = @yield('title')

If no, then is there any way to get the value of this yield



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

Laravel Spark API call validation not returning errors on fail but showing login page

I am working on a Laravel API and have a resource route for adding events.

I have added a form request for validation, but when using Postman with a correct API key set the validation failure will return a 200 status and show the login page as if unauthorised.

API route:

Route::group([
    'middleware' => 'auth:api',
    'prefix' => 'v1'
], function () {
    Route::resource('events', 'Api\V1\EventController');
});

Form request:

<?php

    namespace App\Http\Requests;

    use Illuminate\Foundation\Http\FormRequest;

    class StoreEvent extends FormRequest
    {

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' => 'required'
        ];
    }
}

In my controller:

public function store(StoreEvent $request)
{
    return Event::create([
        'user_id' => Auth::user()->id,
        'name' => $request->name,
    ]);
}

If I have a name field set in the request, it correctly adds a value but not having a name field returns the login page.



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

Array to string conversion when seeding a table

When trying to seed a table, it's showing an 'array to string conversion' error.

This is the output of the error:

[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `reviews` (`user_id`, `name`, `location`, `header`, `comments`, `identifier`, `stars`, `privacy`, `actioned`, `appr
oved`, `created_at`) values (10, Bradley Davis, Paulastad, Commodi quas expedita eum., Voluptas magni iusto nemo ea vitae harum quasi., 6c621319-c6ba-41c1-bb0b-696b602470
ef, 5, 1, 0, 1, 2017-03-25 11:44:12))

Table structure:

Schema::create('reviews', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id');
    $table->string('name')->nullable();
    $table->string('location')->nullable();
    $table->string('header')->nullable();
    $table->string('comments')->nullable();
    $table->uuid('identifier');
    $table->integer('stars')->nullable();
    $table->boolean('privacy')->default('1');
    $table->boolean('actioned')->default('0');
    $table->boolean('approved')->default('0');
    $table->nullableTimestamps();
});

Seed function:

for ($i = 1; $i < 41; $i++) {

    $name = User::where('id', $i + 9)->pluck('name')->all();
    $uuid = Uuid::generate(4);

    $review = [
        'user_id' => $i + 9,
        'name' => $name,
        'location' => $faker->city,
        'header' => $faker->sentence($nbWords = 3, $variableNbWords = true),
        'comments' => $faker->text($maxNbChars = 50),
        'identifier' => $uuid,
        'stars' => [1, 2, 3, 4, 5][rand(0, count([1, 2, 3, 4, 5]) - 1)],
        'privacy' => [1, 0][rand(0, count([1, 0]) - 1)],
        'actioned' => [1, 0][rand(0, count([1, 0]) - 1)],
        'approved' => [0, 1][rand(0, count([0, 1]) - 1)],
        'created_at' => Carbon::now()->subWeeks(array_rand([2, 3, 4, 5, 6, 7], 1))
   ];
}

DB::table('reviews')->insert($review);

print_r($review):

Array
(
    [user_id] => 10
    [name] => Array
        (
            [0] => David Robertson
        )

    [location] => Lake Suzannechester
    [header] => Repellendus aut alias exercitationem.
    [comments] => Sunt non temporibus pariatur totam aut qui.
    [identifier] => Webpatser\Uuid\Uuid Object
        (
            [bytes:protected] => �a�?�IB��"�mLC�
            [hex:protected] =>
            [string:protected] => d51961bb-3fcf-4942-a0d9-22a56d4c4392
            [urn:protected] =>
            [version:protected] =>
            [variant:protected] =>
            [node:protected] =>
            [time:protected] =>
        )

    [stars] => 4
    [privacy] => 1
    [actioned] => 1
    [approved] => 1
    [created_at] => Carbon\Carbon Object
        (
            [date] => 2017-03-04 12:04:01.225487
            [timezone_type] => 3
            [timezone] => UTC
        )

)



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