jeudi 26 novembre 2015

Issues importing XML with Laravel Package orchestral/parser

I have this XML that i'm trying to import:

    <products>
<product product_id="62" title="Product Title" description="<p>desc</p>" price="40" brand="" weight="100" in_stock="Y"/>
<product product_id="63" title="Product Title" description="<p>desc</p>" price="40" brand="" weight="100" in_stock="Y"/>
</products>

I'm using Laravel 5 and this package: http://ift.tt/1KBdWon

So i'm running this code:

    $xml = XmlParser::load('http://ift.tt/1OtIkWc');


    $product = $xml->parse([
    'product_id' => ['uses' => 'product::product_id'],
    'title' => ['uses' => 'product::title'],
    'description' => ['uses' => 'product::description'],
]);
    dd($product);

But it's just returning a single product in an array which isn't even the first or last one in the XML. So i'm a bit confused.

Anyone got any ideas?

Thanks.



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

Laravel - insert multiple models from appended inputs

I'm new to Laravel and I'm trying to insert n models from n appended html inputs Does Laravel's `Eloquent have a better way than this ?

public function store(Request $request, Domain $domain, Server $server)
{
    $new_domain = $domain->create($request->all());
    $server->fill($request->only(['srv_hostname','srv_ip','srv_port']));
    $servers = array();
    $total = count($server['attributes']['srv_hostname']);
    for ($i=0;$i<$total;$i++){
        $p = new Server;
        $p->domain()->associate($new_domain);
        $p->srv_hostname = $server['attributes']['srv_hostname'][$i];
        $p->srv_ip = $server['attributes']['srv_ip'][$i];
        $p->srv_port = $server['attributes']['srv_port'][$i];
        $p->save();
    }
    return redirect()->route('domains.index');
}



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

Laravel 5.1: SQL query 'where LIKE %word%word%word%' not working

Keep in mind I have minimal SQL experience, so I may be doing it all wrong.

I'm trying to set up search for a table but simply searching for the string a user enters is not ideal because though something may come up for "steve", if a user types "steve jobs story", nothing will match if that doesn't exist, as it'll be looking for that whole string instead of looking for each word respectively.

I tried to break it down by exploding the string into an array and then imploding that and separating it with %'s, so a search like "steve jobs story" would be "steve%jobs%story", and with my query it would be "%steve%jobs%story%". When I try searching this, I get no error but the query finds nothing, whereas when I just type one word it works, so I'm guessing what I'm trying to do isn't allowed.

Can someone point me in the right direction? Here is my controller/model:

// Controller

$query = $request->get('q');

$explodedQuery = explode(" ", $query);
$newQuery = implode("%", $explodedQuery);

$articles = Article::isLikeTitle($newQuery)
                   ->isLikeBody($newQuery)
                   ->latest('published_at')
                   ->published()
                   ->paginate(10);

// Model

public function scopeIsLikeTitle($query, $q)
{
    return $query->where('title', 'LIKE', "%$q%");
}

public function scopeIsLikeBody($query, $q)
{
    return $query->where('body', 'LIKE', "%$q%");
}



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

Laravel 5 - Helper on Blade not working

I have this error when I used {{ Helper::test(); }} on a blade

enter image description here

and on my config/app.php, I already have enter image description here

and this is inside of my Helper.php

<?php namespace App;

class Helper {
    public static function test() {
        return "wa";
    }
}

and I already done the composer.json then run the composer dump-autoload

...
"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "app/Helper.php"
        ]
    },
...

I don't know what I missed, is there any suggestion to be able to use the helper on a blade on a laravel 5?



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

Laravel 5.1 firstOrNew

I want to be able to insert a new record into the database if it doesn't already exist. If it does exist I want to update the existing record with the new info.

Basically, the field that I want to check to see if it exists is called 'token'.

So, I have tried something like this:

$this->timesheet->firstOrNew(['token' => '12345'])->save();

This successfully creates the new row.

How do I pass in the other fields that I want to insert/update? For example first_name, last_name?

Can I do something like:

$this->timesheet->firstOrNew(['token' => '12345'])->update(['first_name' => 'Bob', 'last_name' => 'Smith'])->save();



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

Laravel5 - Non-static method should not be called statically

I don't know what is this error. Please someone give me some explaination

on my UserController.php

class UserController extends Controller {
    public function viewCard($card_id) {
        return Tag::test($card_id);
    }
}

and on my model Tag.php

class Tag extends Model {
    public function test($card_id){
        return DB::SELECT(DB::RAW("SELECT name FROM tagmap tm, tags t WHERE t.id = tm.tag_id AND tm.card_id = :card_id"), ['card_id'=>$card_id]);
    }
}

i don't know where it fails, where I do wrong...



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

Laravel 5 Route with multiple ID’s

I would like to pass two sets of ID’s into a route.

The first ID is that of the authenticated user so for example 3 and the second is that of a candidate.

So what I would like it to do is: vault/3/candidates/120

Here is the route I want to have:

Route::get('vault/{id}/candidates/{id}', 'CandidateController@centreCandidatesShow');

Using:

ublic function centreCandidatesShow($id)
{
    $candidate = Candidate::with('qualification')->find($id);

    return view('vault.show', compact('candidate'));
}

Could someone let me know if this is even possible and if so how?

I’m sorry if this question sounds stupid or is not even possible. I’m still very new to this.

Many thanks.



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