samedi 18 novembre 2017

Laravel Backpack - Set extra attributes before page save

In my PageTemplates.php I have a field like this:

$this->crud->addField([
    'name' => 'adres',
    'label' => 'Adres',
    'type' => 'address',
    'fake' => true,
]);

Now I would like to save also the latitude and longitude of the address they give in (if it can be found). I've copied the PageCrudController and changed the config in config/backpack/pagemanager.php to:

return [
    'admin_controller_class' => 'App\Http\Controllers\Admin\PageCrudController',
    'page_model_class'       => 'App\Models\Page',
];

In my store function I have:

public function store(StoreRequest $request)
{
    $address = $request->request->get('adres');
    $addressObj = app('geocoder')->geocode($address)->get()->first();

    if($addressObj)
    {

    }

    $this->addDefaultPageFields(\Request::input('template'));
    $this->useTemplate(\Request::input('template'));

    return parent::storeCrud();
}

But what do I place in the if statement? How can I add (= set) an extra field to the extras field in my database?



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

Laravel 5.5 socialite integration shows error formatRedirectUrl() must be of the type array, null given

I am using "laravel/socialite": "^3.0", to facebook login. But it shows
an error 
Type error: Argument 1 passed to Laravel\Socialite\SocialiteManager::formatRedirectUrl() must be of the type array, null given, called in /var/www/html/mas/vendor/laravel/socialite/src/SocialiteManager.php.

It happens when I am calling the below function in my login controller

public function socialLogin($social)
{
    return Socialite::driver($social)->redirect();
}



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

Laravel - how to validate sum of values to other input value

i have a form that user enter the amount of cheque and choose the bills that concernded this cheque , so the sum of bills amounts must be equal to cheque's amount .

i have one input for cheque number , one for date of cheque and other for amount of cheque.

i used foreach to generate table of bills with checkbox input in each bill so it return an array of checked values to my controller .

here is my html :

<form method="post" action="" data-parsley-validate class="form-horizontal form-label-left">

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="num_cheque">N° Chèque <span>*</span>
                                              </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input value="" id="num_cheque" name="num_cheque" class="form-control col-md-7 col-xs-12">                                @if ($errors->has('num_cheque'))
                            <span class="help-block"></span> @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="date_cheque">Date Chèque <span class="required">*</span>
                                              </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" value="" id="date_cheque" name="date_cheque" class="form-control col-md-7 col-xs-12">                             @if ($errors->has('date_cheque'))
                            <span class="help-block"></span> @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="montant">Montant du Chèque <span class="required">*</span>
                                              </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input value="" id="montant" name="montant" class="form-control col-md-7 col-xs-12">                             @if ($errors->has('montant'))
                            <span class="help-block"></span> @endif
                        </div>
                    </div>

                    <div class="ln_solid"></div>


                    <h3>Selectionner les factures concernés :</h3>
                    <div class="table-responsive">
                        <table class="table table-striped jambo_table bulk_action fact">
                            <thead>
                                <tr class="headings">
                                    <th>

                                    </th>
                                    <th class="column-title">N° Facture </th>
                                    <th class="column-title">N° BL</th>
                                    <th class="column-title">N° BC</th>
                                    <th class="column-title">Region</th>
                                    <th class="column-title">Lieu de livraison</th>
                                    <th class="column-title">Date Facture</th>
                                    <th class="column-title">Montant Total TTC</th>

                                </tr>
                            </thead>

                            <tbody id="tbody">
                                @if(count($factures)) @foreach ($factures as $row)
                                <tr class="even pointer">
                                    <td class="a-center ">
                                        <input type="checkbox" id="fact_id" name="fact_id[]" value="" class="flat">
                                    </td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                @endforeach @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="ln_solid"></div>

                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-6">
                            <input type="hidden" name="_token" value="">
                            <button type="submit" class="btn btn-success">Ajouter</button>
                        </div>
                    </div>
                </form>

what i have to do ?? Can i use jquery ? if yes , how ??



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

Incomplete Laravel page view

I am developing a web application in Laravel 5, I basically fetch data from database in controller method and pass it the the view which is then shown in a table. When i request that page, sometime complete data is not shown. Like it misses couple of rows randomly, it happens randomly every once in a while, sometime plain html is shown in browser and sometime the script as well, but when i refresh the page it shows complete information on the page properly. What possible reason can be behind this?



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

Laravel Backpack - Upload multiple in PageTemplate

I'm trying to upload multiple images on page edit form. In my PageTemplates.php I have:

$this->crud->addField([ 
    'name' => 'images',
    'label' => 'Fotos',
    'type' => 'upload_multiple',
    'upload' => true,
    'disk' => 'uploads',
    'hint' => 'Some hint text.',
    'fake' => true
]);

In my Page model I have:

public function setImagessAttribute($value)
{
    $attribute_name = "images";
    $disk = "uploads";
    $destination_path = "images/pages";

    $this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}

In my $disks array in config/filesystems.php I have:

'uploads' => [
    'driver' => 'local',
    'root' => public_path('uploads'),
],

But when I try to save the page I have 2 problems:

  • Images aren't saved in folder (folder is writeable!)
  • Not saved in database

In my database extras field for that page I get:

"images":[  
  {  

  },
  {  

  }
],

What am I doing wrong?



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

Laravel 5: Output tFPDF

I want to use tFPDF in Laravel 5.5. I added the package with composer and then I tried to output it the according to the docs but nothing worked.

I tried to output it directly to the browser:

Route::get('/test',function(){
        $pdfLibrary = new tFPDF\PDF();
       $pdfLibrary->AddPage();

       $pdfLibrary->AddFont('DejaVuSansCondensed', '', 'DejaVuSansCondensed.ttf', true);
       $pdfLibrary->SetFont('DejaVuSansCondensed', '', 14);

       $pdfLibrary->Write(8, 'Hallo!');
       $pdfLibrary->output();           
});

but the sceen was just blank. When I tried return $pdfLibrary->output(); then it just returned

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�u�� �@S�)>+�p�.......

I also tried to simply save the pdf to a file, but even

$pdfLibrary->output('F', storage_path() . '/test.pdf');

did not work.

How can I save & output the pdfs created by tFPDF ?



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

ReflectionException Class UserController does not exist Laravel5.4

Everytime i hit the Submit Button i got this problem ReflectionException Class UserController does not exist

 <?php
 namespace app\Http\Controllers;
  use App\User;
  use Illuminate\Http\Request;




   class UserController extends Controller {

   public function postSignUp(Request $request)
        {
       $email = $request['email'];
        $first_name = $request['first_name'];
        $password = bcrypt($request['password']);
        $user = new User();
         $user->email =$email;
         $user->first_name=$first_name;
          $user->password = $password;
           $user->save();

            return redirect()->back();

                   }

               public function postSignIn(Request $request)
                   {

                       }
                       }

My route file:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;


class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
       Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));


        Route::post('/signup',[
            'uses'=>'UserController@postSignUp',
            'as'=>'signup'
        ]);



    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}



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