Tuesday, February 28, 2017

Vagrant not working on my Windows 10

I installed a Laravel Homestead (per project installation). After a successful installation of all the dependencies, I tried to run vagrant up but this errors are being thrown.

The guest machine entered an invalid state while waiting for it to boot. Valid states are 'starting, running'. The machine is in the 'unknown' state. Please verify everything is configured properly and try again.

This is my Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
hostname: rebuy.dev.se
name: rebuy.dev.se
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: "E:/projects/rebuy"
      to: /home/vagrant/rebuy

sites:
    - map: rebuy.se.dev
      to: "/home/vagrant/rebuy/public"

databases:
    - homestead

I had already added to my /Windows/system32/drivers/etc/hosts the IP for my app.

192.168.10.10   rebuy.se.dev

I'm using Vagrant 1.9.0 and Oracle VM Virtual Box. Not sure what's causing this error, since I successfully run vagrant on my other computer. Any help will be very much appreciated. Thanks!

enter image description here




via dexterb

Laravel 5.3 doing join on pivot table with same models

I posted a previous question seeing if what I'm trying to do could be done with eloquent relationships and it looks like it isn't possible ( Laravel 5.3 Many to many relationship with same model ) .

So now I'm trying to write the query with query builder and have this:

return $relationships = DB::table('landlord_contact_landlord_contact')
            ->where('landlord_contact1_id', $id)
            ->orWhere('landlord_contact2_id', $id)
            ->join('landlord_contacts', function($join){
                $join->on('landlord_contacts.id', '=' , 'landlord_contact_landlord_contact.landlord_contact1_id');
            })
            ->get(['landlord_contact_landlord_contact.id AS relationshipID','landlord_contact_landlord_contact.type' , 'landlord_contacts.*']);

Lets say I have a contact named Jim with an id of 1

And another contact named Tom with an id of 2

What I'm trying to do is have each contact have relationships with other contacts. The table "landlord_contact_landlord_contact" is the pivot table and has "landlord_contact1_id" and "landlord_contact2_id" to join the 2 contacts. Now if I create a record, connecting Jim to Jon and have landlord_contact1_id = 1 and landlord_contact2_id = 2 that's great. But how can I make the query work on both columns so I don't have to create 2 records for each relationship.

I want to search on both columns for the current landlord's id and then do a join either on landlord_contact1_id or landlord_contact2_id depending on which one isn't the current landlords ID.

Note : In my previous post, I used the table name User, but have since renamed everything to Landlord Contacts




via tecshaun

Laravel 5.3 backend and Vue 2.0 form to create user

I'm having trouble authenticating users via Vue 2.0.

In Vue I have a form in which the user enters all his data and submits it via POST to a Laravel (web route) endpoint.

Then the user is created in the UserController method with the supplied data and I'm stuck at this point as I don't manage to authenticate my user after creation and redirecting him to some route (other page).

User creation goes fine...

Can someone explain me rapidly how it should work? (as I understood that I can't redirect from the controller as the data is POSTed via an ajax call).

What's the "right" way to do this as I'm afraid I'm completely mistaken :)

Thanks in advance for your help.




via Charles Dubant

Querying Laravel Eloquent Relationship

I have three tables.

  • Categories
  • Products
  • Brands

I have a relation on my categories table to the products like so:

public function products()
{
    return $this->belongsToMany('App\Product','product_sub_categories','subcategory_id','product_id');
}

I have a relation on my Products table to the brands like so:

public function manuf()
    {
        return $this->belongsTo('App\Brand','brand');
    }

I'm querying the categories table to return products of that category by a certain brand.

For example.

I wan to see all products in Cars category with the brand Fiat.

I've tried the following but I feel Im missing something..

 $search = 'fiat';
 $products = $category->products()->where(function($query) use ($search){
                    $query->brand->name = $search;
                })->get();




via Dev.Wol

Jquery Drag and drop to Update MySql DB in Laravel App

I have 5 tables with data.

I can drag and drop rows and reassign their positions. I am grabbing the ID of the DB record they belong to.

I want to be able to update it from table one to table 2 on the database. I was told not to use AJAX because that handles updating records in the front end and it could be dangerous. I dont know what route to go for or even how to manage it.

I am using Laravel 5.3




via gxrobb

Laravel webpack gives me 0++ in production

On a project using Laravel 5.4 and the new Laravel Mix, I have a weird error when pushing live a website.

When I'm in local, and I run the command npm run dev everything is working perfectly. dev is the following :

"dev": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

This command execute webpack (which I am not very familiar with) and convert sass, js, coffe, etc... to vanilla CSS and JS.

The problem is happening when live like I said when the command is npm run production. production is the following :

"production": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

The traduction is happening correctly but when I go on the website I get the following error :

Uncaught ReferenceError: Invalid left-hand side expression in postfix operation

When I dig a little in the js I find this weird thing happening :

for(var n=t.length;0<n;0++)

So I have 0++ that would need to be n++ and when I make research on the file, I get 115 occurence of the 0++.

I think it is coming from webpack ? a misconfiguration or something ?

Thanks in advance for your help !




via dib258

How to properly use migrations in lumen/laravel?

I want to create several tables with FK on one table. Messing with foreign constraints which are fail on table creation on up method in migrations.

Obviously I should add foreign key only when FK destination table was created, so should I create new migration for each database manipulation, i.e. every time I need to add foreign key ?

or should I use if (Schema::hasTable('Drug')) { ... } approach ?




via Anonymous

Advertisement