samedi 27 août 2016

Http callback is never called, Vue Laravel

Got this in a Vue component (Users.vue). The fetchUsers-function is called but the callback-function is NEVER called. I've tried to attach .error()-func but I get an error of this.$http.get(...).error is not a function.

<template>
    <div class="panel panel-default">
        <div class="panel-heading">Användare</div>

        <div class="panel-body">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Email</th>
                    </tr>   
                </thead>
                <tbody>
                    <tr v-for="user in users">
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script>
    export default {

        name: "Users",

        ready() {
            console.log('Component ready.')

            this.fetchUsers();
        },

        methods: {
            fetchUsers: function() {
                console.log("Fetching users...");

                this.$http.get('/api/user', (data) => {
                    this.$set("users", data);
                });
            }
        }
    }
</script>

I use Laravel's framework that ships with Vue.js. Don't know how it all works but I get the component showing up in the web browser and I get output in the console from this code.



via Chebli Mohamed

Laravel 5: Update record without changing current date/time value of updated_at field

In my Laravel 5 project, I would like to increase the number of views when a visitor come/refresh on the product page like:

$rds = Product::whereId($id)->first();
$rds->hits++;
$rds->save();

The problem is that the field: updated_at automatically update, which is not what I want at all because I would like to change only field: hits, not update_at field.

If I set $rds->updated_at = false; the field is updated to be '0000-00-00 00:00:0'.

Could you advise how to prevent updated_at field from automatically changing for only certain function?

Best Regards, Naren



via Chebli Mohamed

Laravel 5 - How to seed table automatically after deploying an app?

I have a certain data that must be in table in order for my app to work, otherwise i get an error message.

For example if YOU or anyone else pulled my app from github and if you run php artisan migrate and then try to test the app you would get an error: data doesn't exist or something like that. and it's because there is no data in table.

So ideal solution would be after running:

 php artisan migrate

that you also get this needed data in that table.

This should be done somehow with the seeder but i don't know how. Can anyone help and give me an example?



via Chebli Mohamed

how to pass form data using angular js in laravel API

i have on site which front part handled using Angularjs and backend for admin is in laravel. i want to store data in database which will be passed using Angularjs

can anyone help me ???



via Chebli Mohamed

summernote (data not saving in DB) (laravel 5.2)

I am using laravel 5.2 and integrating summernote js in the site.

I want that when user fills the form and click on save ,all the data get stored in Database.

It worked for a single field but not for two or more.

my view:

    <form action="" id="acc" class="ac" method="post">
  <div class="col-lg-3"><label>Estado</label>

  @foreach($accounts as $account)
  @if($user== $account->user)
  {!! $account->estado !!}
  <textarea  style="display:none;" name="textfield4" id="textfield4"></textarea></div>

  <div class="col-lg-2 es" id="estado"></div>


 <a span class="fa fa-heartbeat"  id="sex" aria-hidden="true">
    </span></a>
</div>
  <div class="col-lg-4"></div>
</div>
<div class="row">
  <section class="col-lg-3"><div><br><label for="textfield5">I'm Good At:</label>


   <p>{!! $account->goodat !!}</p>


   <textarea  style="display:none;" name="textfield5" id="textfield5"></textarea></div>
  <div class="col-lg-2 es" id="goodat"></div>
   @endif
  @endforeach

my JS in view:

 <script>

var edit = function() {
  $('#estado').summernote({focus: true});
   $('#goodat').summernote({focus: true});
};

var save = function() {
  var makrup = $('#estado').summernote('code');
  $('#estado').summernote('destroy');

  var makrup = $('#goodat').summernote('code');
  $('#goodat').summernote('destroy');
};

$(".acc").submit(function(e) {
     var self = this;
     e.preventDefault();


    //$('#estado').summernote('destroy');
     var estado = $('#estado').summernote('code');
     $("#textfield4").html(estado); //populate text area



      var goodat = $('#goodat').summernote('code');
     $("#textfield5").html(goodat); //populate text area
     self.submit();
     return false; 


});



</script>

my controller:

 se App\Account;

use Illuminate\Support\Facades\Auth;


class AccountController extends Controller
{

 public function account(Request $request)
    {

        $account = new Account();
        $account->estado = $request->input('textfield4');
        $account->goodat = $request->input('textfield5');
        $request->user()->accounts()->save($account);


        return redirect()->route('myplace',['username'=>Auth::user()->username]);
    }



}



via Chebli Mohamed

One-To-Many Relation with Pivot Table

I have 2 tables Manufacturers and Suppliers ,and they have Many-to-Many relation

Schema::create('manufacturers', function (Blueprint $table) {
       $table->increments('id');
       $table->string('name')->unique();
       $table->timestamps();
}); 

  Schema::create('suppliers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('location');
        $table->timestamps();
 ​ });

so i created a pivot table called "manufacturer_supplier" and it works fine.

Schema::create('manufacturer_supplier', function (Blueprint $table) {

$table->increments('id');
$table->integer('manufacturer_id')->unsigned()->index();
$table->integer('supplier_id')->unsigned()->index();
$table->timestamps();

$table->foreign('manufacturer_id')->references('id')->on('manufacturers')->onDelete('cascade');
$table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('cascade');
 });

My confusion comes from adding a new table "devices"

Schema::create('devices', function (Blueprint $table) {

$table->increments('id');
$table->string('serial')->unique();
$table->string('name');
​$table->integer('supplier_id')->unsigned()->nullable();
$table->integer('manufacturer_id')->unsigned()->nullable();
$table->text('notes')->nullable();
$table->timestamps();

$table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('cascade');
$table->foreign('manufacturer_id')->references('id')->on('manufacturers')->onDelete('cascade');
 });

where i want to have a one-to-many relation with each of suppliers and manufacturers , so i would have a select list of manufacturers and then populate the next list from with suppliers from Pivot table that relate to the selected manufacturer.

currently my "device"​ model has the following relations which it relate them to the original table not the pivot so it doesn't work

//5
public function manufacturer(){

return $this->belongsTo('App\Manufacturer');
}
//6

public function supplier(){

return $this->belongsTo('App\Supplier');
}

I haven't done that before so i'm curious to know what will be the best fix for this to work. Thanks a lot ,



via Chebli Mohamed

PHP PHANTOMJS : Error when executing PhantomJs procedure

I'm trying to use PHP Phantom with Laravel project on Ubuntu (php version > 5.5). Followed the installation steps mention here : http://ift.tt/1xQvSFp .

I'm getting the following error :

Error when executing PhantomJs procedure - File does not exist or is not ex

ecutable: bin/phantomjs Even tried to set bin directory using $client->setBinDir('/path/public/bin'). Also tried both absolute and relative path but following error was thrown :

Call to undefined method JonnyW\PhantomJs\Client::setBinDir() Tried everything found over the internet to fix this.



via Chebli Mohamed