vendredi 1 février 2019

I want to change language string value using controller. How generate localisation string files dynamically?

I have create files for english and german language statically in laravel rscources/lang/en and resources/lang/de folders. i want to change the string of particular lang key using my controller. how i can do ??



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2S1m9lp
via IFTTT

PHP function call_user_func() in Laravel

Hello guys! :D

I have a problem with PHP function call_user_func() in Laravel project. I am testing this function in plain PHP (v 7.0) project and work, but in Laravel doesn't work.

What exactly I want?

I want take parametar from URL (this is a string OK?). When I take parametar (string), I put in function and call object and static method. It is a dynamic calling of objects. For example:

function call_user_func($param.'::all()')

$param is string from URL and representation my Model

all() is method

I get error:

call_user_func() expects parameter 1 to be a valid callback, class 'Brand' not found

P.S.

I include Brand class

use \App\Brand

Do you have solution how to call an object over a string?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2DMiyPh
via IFTTT

Laravel Query Builder Multiple Select And Named Columns

I'm new at using Query Builder, today I stuck on Query Builder.I'm trying to do name column also multiple select. Here is what I'm trying to convert query builder :

SELECT 
users.name,
users.surname,
users.avatar_path,
users.city_id,
users.district_id,
users.neighboor_id,
cities.name as city_name
FROM users,cities
WHERE users.city_id = cities.id
AND users.name LIKE 'bar%'

is there any way without using DB::raw() ?

Thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Bf3rfM
via IFTTT

How to send XML POST request with Guzzle to web service API using Laravel?

I am trying to post a request to my Web API, using Laravel Guzzle Http client. However, I am getting errors trying to post the request. The data I want to send is XML as the API controller is built in XML return format.

I have tried all sorts of methods to post the request with Guzzle but it is yet to work.

public function createProperty(Request $request)
 {
    $client = new Client();

    $post = $request->all();


    $create = $client->request('POST', 'http://127.0.0.1:5111/admin/hotel', [
        'headers' => [
            'Content-Type' => 'text/xml; charset=UTF8',
        ],
        'form-data' => [
           'Name'           => $post['hotel_name'],
           'Address'        => $post['address'],
           'Phone'          => $post['phone'],
           'Email'          => $post['email'],
           'Website'        => $post['website'],
           'Latitude'       => $post['latitude'],
           'Longitude'      => $post['longitude'],
           'Tags'           => $post['tags'],
           'Priority'       => $post['priority'],
           'Visible'        => $post['visible'],
           'Stars'          => $post['stars'],
           'Description'    => $post['description'], 
           'Facilities'     => $post['facilities'],
           'Policies'       => $post['policies'],
           'ImportantInfo'  => $post['important_info'],
           'MinimumAge'     => $post['minimum_age']
       ]                            
    ]);
    //dd($create->getBody());

    echo $create->getStatusCode();
    echo $create->getHeader('content-type');
    echo $create->getBody();
    $response = $client->send($create);

    $xml_string = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $create->getBody());
    $xml_string = $create->getBody();
    //dd($xml_string);
    $hotels = simplexml_load_string($xml_string);

    return redirect()->back();
}

I expected the result to POST to the web service and save data to database, but however I got the error "Client error: POST 'http://127.0.0.1:5111/admin/hotel' resulted in a '400 bad request' response. Please provide a valid XML object in the body



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2UwgWin
via IFTTT

Select Multiple dropdwon list from database in Laravel

in my web application i have added multiple data to database from json_encode using multiple select options.

in my database column its shown as below.

["Agriculture & Food Processing","Automobiles","Banking & Financial Services"]

Now i want to retrieve these data to edit and update. my view is like attached image

view

and my code is like below

<div class="form-group">
<label for="industry">Intrsting Industry</label>
<select id="industry" name="industry[]" class="form-control" multiple>
    <option value="">Select Option  </option>
    <option>Agriculture &amp; Food Processing</option>
    <option>Automobiles</option>
    <option>Banking &amp; Financial Services</option>
    <option>BPO / KPO </option>
    <option>Civil &amp; Construction</option>
    <option>Consumer Goods &amp; Durables</option>
    <option>Consulting</option>
    <option>Education</option>
    <option>Engineering</option>
    <option>Ecommerce &amp; Internet</option>
    <option>Events &amp; Entertainment</option>
    <option>Export &amp; Import</option>
    <option>Government &amp; Public Sector</option>
    <option>Healthcare</option>
    <option>Hotel, Travel &amp; Leisure</option>
    <option>Insurance</option>
    <option>IT &amp; Telecom</option>
    <option>Logistics &amp; Transportation</option>
    <option>Manufacturing</option>
    <option>Manpower &amp; Security</option>
    <option>News &amp; Media</option>
    <option>NGO &amp; Non profit</option>
    <option>Pharmaceutical</option>
    <option>Real Estate</option>
    <option>Wholesale &amp; Retail</option>
    <option>Others</option>
  </select>

SO how can i selected above list from database.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WBWCxJ
via IFTTT

Fire Laravel events on touch

this is my scenario: I'm using Laravel 5.5.x. I have two models, linked in one to many way.

class Artwork extends Model
{
   //It has timestamps
   protected $table = 'artworks';
   protected $fillable = [
        'artwork_category_id'
   ];
   public function artworkCategory()
    {
        return $this->belongsTo('App\Models\ArtworkCategory');
    }
}

class ArtworkCategory extends Model
{
    use SoftDeletes;

    protected $touches = ["artworks"];

    /**
     * @var string
     */
    protected $table = 'artwork_categories';
     protected $fillable = [
        'category_name',
        'acronym',
        'deleted_at'
    ];

    public function artworks()
    {
        return $this->hasMany('App\Models\Artwork');
    }
}

Touch works correctly, so when I update an artwork category the related artworks updated_at field is updated.

But I need to listen the "touch" event on each artwork. I've tried inserting "updated" listener on boot method in AppServiceProvider, but it is not fired.

Artwork::updated(function ($model){
            \Log::debug("HERE I AM");
        });

I've tried using an observer, but no luck.

class ArtworkObserver
{
    public function updated(Artwork $artwork)
    {
        dd($artwork);
    }
}

Boot method in AppServiceProvider:

Artwork::observe(ArtworkObserver::class)

Question: Could somebody show me the right way to do it? Or tell me where am I wrong? I was not good enough to find an example that helps me how to do it.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2RsLnE1
via IFTTT

Why in laravel 5 / mysql 5 saving float value is rounded?

In my laravel 5.7 / mysql 5.7.25-0ubuntu0 app using eloquent I save float value (money), but value is rounded to int, so for value '12346301.67' I trace sql as :

   UPDATE `storage_spaces` set `updated_at` = '2019-02-01 10:31:41', `selling_range` = '12346301.67' 
    WHERE `id` = '1377' 

But in db I see value as “12346302.0000000”

Field defined as :

CREATE TABLE `storage_spaces` (
...
    `selling_range` FLOAT(17,7) NULL DEFAULT NULL,
...

What is wrong and how to fix it?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2HIGSpj
via IFTTT