lundi 29 août 2016

Dynamically adding data to div from model on dropdown select

I've been searching for quite a while and can't find a solid answer for this. I'm using Laravel 5.3 as well as Laravel Collective for the forms and Chosen to manipulate my select boxes.

Basically I have a select dropdown, which has values in it that are pulled from the database. When I select a value, I wan't to populate each empty 'panel' on the page with the relevant model data for the selected item.

So for example when I select 'admin' I want to look in the 'roles' table and display 'description' and 'display_name' associated with the selected value. Furthermore I want to get the associated permissions for that entry and display them as well.

Here is my form:

                            <div class="form-group">
                                <script type="text/javascript">
                                    $(document).ready(function() {
                                        $(".role").chosen()
                                    });
                                </script>
                                {!! Form::label('Role') !!}
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="fa fa-user-plus" aria-hidden="true"></i></div>
                                    {!! Form::select('role', $roles, null, ['id' => 'role', 'class' => 'select-width-100 form-control role']) !!}
                                </div>
                            </div>
                            {!! Form::label('Display Name') !!}
                            <div class="panel panel-default">
                                <div class="panel-body" name="d_name" id="d_name">

                                </div>
                            </div>
                            {!! Form::label('Description') !!}
                            <div class="panel panel-default">
                                <div class="panel-body" name="description" id="description">

                                </div>
                            </div>

                            <div class="input-group">
                              <span class="input-group-btn">
                                <button class="btn btn-danger" type="submit" name="update">Update</button>
                              </span>
                            </div>

I know there is a way to fire ajax and receive it with a 'route::get' but I have no idea how to do this or where to start. My Jquery skills are severely lacking.

Any help would be greatly appreciated.



via Chebli Mohamed

Laravel 5. Retrieve data from DB::select

Code:

        $best_price = DB::select('Some SQL statement');

        foreach($best_price as $best_price_id) {
            $best_price_id->id;
        };


        $product->best_price_id = $best_price_id;

        return $product->best_price_id;

Result:

The Response content must be a string or object implementing __toString(), "object" given.

Definately I am retrieving information from the DB incorrectly. Please suggest better option.



via Chebli Mohamed

Please assist with complex mysql query converting for use in Laravel 5

Here is my query.. I have tried several different ways to get the proper result while formatting for laravel 5, if anyone can assist with the proper format I would greatly appreciate it

  SELECT z.id, z.address, z.city, z.state, z.zip, 
    z.latitude, z.longitude, 
      (p.distance_unit 
        * DEGREES(ACOS(COS(RADIANS(p.latpoint)) 
        * COS(RADIANS(z.latitude)) 
        * COS(RADIANS(p.longpoint) - RADIANS(z.longitude)) 
        + SIN(RADIANS(p.latpoint)) 
        * SIN(RADIANS(z.latitude))))) AS distance 
  FROM locations AS z 
  JOIN ( 
    SELECT ? AS latpoint, 
           ? AS longpoint, 
           ? AS radius, 
           ? AS distance_unit 
    ) AS p 
  WHERE z.latitude 
    BETWEEN p.latpoint  - (p.radius / p.distance_unit) 
    AND     p.latpoint  + (p.radius / p.distance_unit) 
  AND   z.longitude 
    BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) 
    AND     p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) 
  ORDER BY distance 
  LIMIT ?

my variables are in order:

$latpoint
$longpoint
$radius
$distance_units
$limit



via Chebli Mohamed

How do we concatenate using blade template engine Laravel

I am new to Laravel and don't know if it is possible at all to concatenate a string to a blade variable.

I want to display the name of the author with the ~ sign concatenated to the author's name from the left. Here is my code.

<div class="author">~</div>

What I want is if the author is set, it should be displayed with the ~. How do I concatenate this? Thanks for any help



via Chebli Mohamed

how to redirect different pages in Laravel 5.2

I need redirect user pages according to status of the user. I wrote a method in My Controller in Laravel 5.2 status 1 is working but when I add else and else if function it generate following errror.

FatalErrorException in ProjectCollaboratorsController.php line 219: syntax error, unexpected 'return' (T_RETURN)

My controller method is folllowing

public function show($id){
 if (Permission::where('status', 1)->where('project_id', $id)->exists()){

    $project = Project::find($id);
    $tasks = $this->getTasks($id);
    $files = $this->getFiles($id);
    $comments = $this->getComments($id);
    $collaborators = $this->getCollaborators($id);
    $permissions = $this->getPermissions($id);



    return view('collaborators.show');
    }
else{

    (Permission::where('status', 2)->where('project_id', $id)->exists()) 
         return view('collaborators.manager');

}

else if {

(Permission::where('status', 3)->where('project_id', $id)->exists()) 
         return view('collaborators.user');
}
    }



via Chebli Mohamed

Laravel5 whereRaw not working to parameterize column name

I'm trying to build the column sent_storename with my whereRaw statement. But when I try to concatenate the values, the query doesn't work. When I fix the column it works. How can I do this?

$query = $this->model->getQuery()->where('products.environment_hash', $hash )->whereRaw('products.deleted_at is null');
$query->select('sku_config','name', 'stock_quantity', 'color', 'size', 'special_price', DB::raw('(special_price/default_price-1)*100 as profit_mark'));
$query->leftJoin('ads', 'ads.product_id', '=', 'products.id');
$query->whereRaw("products.sent_? = 0", array('storename'));



via Chebli Mohamed

My Jobs are getting inserted into the table. But they aren't executing. What should I Do?

"php artisan queue:work --daemon"(Supervisor) commands are already running in the background. Jobs are also getting inserted into the job table. But They are not executing..???



via Chebli Mohamed