samedi 1 avril 2017

pass a static value to a controller from routes in laravel

i would like to pass a static value(variable or a static string) from route definition to a controller. for example if consider the following route:

Route::get('/', [
      'uses' => '\Controllers\FoController@show',
      'as' => 'show'
]);

i want to pass a variable(ex, $var1) to that, and then can access to that in the FoController constructor or other controller methods , so i don't like that variable's value shows in the url. how can i do this? thanks...



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

Formating numbers with trailing zeros in Blade view

I have the following code in a Blade view:

@for ($i = 1; $i <= 99; $i++)
    <div id="player-"></div>
@endfor

Which generates divs with ids player-1, player-2, player-3, etc. But what I really need is to have the ids player-01, player-02, player-03, etc. Is there a function in blade to do that like printf in PHP? or using a ternary operator is the best way around?

(The ternary operator works fine when only one zero needs to be added, but doesn't work that fine when more zeros are needed)



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

Laravel Mix scripts() has no effect

I am using Laravel 5.4.

I am trying to copy every single node_modules vendor file in a single vendor.js, however I am having some difficulties at making mix.scripts() work in my webpack.mix.js configuration file.

webpack.mix.js

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js');

mix.copy('node_modules/pickadate/lib/themes/classic.css',      'public/css/vendor/pickadate/themes/classic.css');
mix.copy('node_modules/pickadate/lib/themes/classic.date.css', 'public/css/vendor/pickadate/themes/classic.date.css');

mix.scripts([
    'node_modules/pickadate/lib/picker.js',
    'node_modules/pickadate/lib/picker.date.js'
], 'public/js/vendor.js');

mix.sass('resources/assets/sass/app.scss', 'public/css/app.css');
mix.sass('resources/assets/css/lorde.css', 'public/css/lorde.css');

mix.options({
  processCssUrls: false
});

This is what appears on console:

                                   Asset         Size  Chunks                     Chunk Names
                              /js/app.js      1.23 MB       0   [emitted]  [big]  /js/app
                            /css/app.css       128 kB       0   [emitted]         /js/app
                          /css/lorde.css      8.75 kB       0   [emitted]         /js/app
                       mix-manifest.json    104 bytes           [emitted]
 css/vendor/pickadate/themes/classic.css      2.76 kB           [emitted]
 css/vendor/pickadate/themes/classic.date.css 6.04 kB           [emitted]

You can see that vendor.js (the file I am trying to build) is ignored completely.

How do I fix this?



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

Laravel Incorrect date value error

I`m trying to create page for add user details to database via form values.it gives me this error when i press the submit button.

enter image description here

Here is my migration field.

 $table->date('gce_ol_year');

Here is the relevant form attribute

     <div class="form-group">
        <label>GCE(O/L) Year:</label>
    <input class="form-control" name="gce_ol_year" type="month" value="2011-08" id="example-month-input">
  </div>

Here is the relevant controller attribute

$item ->gce_ol_year = $request ->gce_ol_year;

Can anyone help me to fix this error? Thanks.



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

Laravel 5.4 detach row

When i want change password user and user table got relationship i made detch, next i can change password but how use attach to add again thats same role what user got?

Route::post('profil/changepassword', function() {
    $User = User::find(Auth::user()->id);
    //$User->roles()->$rola;
    $User->roles()->detach();
if(Hash::check(Input::get('passwordold'), $User['password']) && Input::get('password') == Input::get('password_confirmation')){
        $User->password = bcrypt(Input::get('password'));
        $User->save();
        $User->roles()->attach(1);
        return back()->with('success','Hasło zostało zmienione');
    } 
     else{
        return back()->with('error','Hasło nie zostało zmienione');
    }
});

I made something like that and when user change password it will get role User. When Moderator change password thats same get User role not moderator like got befor. So i ask how i can figure it becouse i will use detach in other funcion and i really dont know how make it.



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

Passing values from routes to controller in laravel

I have a route like so

Route::get('/sales/{id}','SalesController@index');

How can I pass extra values to the index function? In my scenerio I want to pass the /sales as well with the {id} from the route.

Here I get only the id for now from the index function.

public function index($id){
    return $id;
}



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

Cut corners in image PHP

Im working with Intervention Image to make a frame. Now im stuck on a part to cut off the edges. I need 4 of those images to make them fit as a frame. I know i can use the Intervention Image library to rotate the image, but i have no clue to cut those corners. Anyone has a idea how to achieve this?

Original:

Result:



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