general

general

Member Since 3 Years Ago

Bratislava

Experience Points 13,230
Experience Level 3

1,770 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 141
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

13 Sep
9 months ago

general started a new conversation WhereHas With Result Count

I'm trying to create bit complicated query but still not working as expected. My tables:

TABLE_PRODUCTS
id
name

TABLE_PRODUCTS_VARIANTS 
id
product_id
sku

TABLE_PRODUCTS_VARIANTS_PROPERTIES
id
variant_id
property_value_id

TABLE_PRODUCTS_PROPERTIES_VALUES
id
value

What I'm trying to do is filter products based on checked values in filter. For example I want to filter PRODUCTS which have VARIANTS which have PROPERTIES which have VALUES. I have variants in nested array. For example:

[
    0 => [
        0 => Black
        1 => XS
    ],
    1 => [
        0 => Red
        1 => XS
    ]
]

So I need to get all products which have variants which have BOTH properties->values from variants array. I came up with this code but it's not working as expected in case if there are variants arrays with 2 values.

$query->whereHas('variants.properties.propertiesValues', function ($query) use ($variants) {
            $query->whereIn('value', $variants);
        });

I think I need to somehow count VARIANT_PROPERTIES if that variant has both properties... Any ideas?

10 Aug
2 years ago

general left a reply on Mass Assignment Foreign Key Error

@Snapey Yes I have roles 1,2,3

general left a reply on Mass Assignment Foreign Key Error

@Snapey when I dump request there is everything ok:

 +request: ParameterBag {#258 ▼
    #parameters: array:28 [▼
      "_token" => "xTHOgv6Z4fLNLim57c2z6NNnGSVsB2vJ26yCD2rb"
      "name" => "gfdgfd"
      "surname" => "gdgdf"
      "title_url" => "gfdgfdgdgdf"
      "role_id" => "3"
      "email" => "[email protected]"
      "password" => "general"
      "password_2" => "general"
      "profile_valid_start" => null
      "profile_valid_end" => null
      "address" => null
      "city" => null
      "zip" => null
      "country" => null
      "phone" => null
      "cell" => null
      "sex" => null
      "birthdate" => null
      "newsletter" => "1"
      "billing_name" => null
      "billing_ico" => null
      "billing_dic" => null
      "billing_ic_dph" => null
      "billing_address" => null
      "billing_city" => null
      "billing_zip" => null
      "billing_country" => null
      "banned" => 0
    ]
  }

general started a new conversation Mass Assignment Foreign Key Error

I have problem to store new user in db. Update works fine. I don't understand why this happens because few weeks ago it worked. I have 2 tables USERS and ROLES. They have foreign key users.role_id => role.id. When I try to save new user:

public function store(Requests\UserRequest $request)
    {
        $input = $request->except('picture');
        $user = User::create($input);
        //$this->uploadPicture($request,$user->id);
        Flash::success(trans('user.messageNewUser', ['name' => $user->name.' '.$user->surname]));

        return redirect('admin/user');
    }

I get this error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`laravel`.`svk_users`, CONSTRAINT `users_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `svk_roles` (`id`) ON DELETE CASCADE) (SQL: insert into `svk_users` () values ())
27 Jun
2 years ago

general started a new conversation Relationship Store Data

Hi I'm new to Laravel so need little bit help... I have 3 tables with eloquent relationship. Reading data works great but now I'm trying to store new data. In form there are data I want to store into 3 tables. My questions are:

Should I put validation for whole form into PageRequest file? In my form I have inputs for 3 language version and name for input looks like title[en] / title[de] / title[sk]. Whats the best solution to save this inputs with laravel?

Relationship is hasOne and belongsTo...

My store function:

public function store(Requests\PageRequest $request)
    {
        $input = $request->except('image');
        $page = Page::create($input);
        
        Flash::success(trans('page.messageNewPage', ['title' => $page->title[sk]]));
        return redirect('admin/page/sections');
    }
05 Jun
3 years ago

general left a reply on Constructor In Method

@ienderli if I understood you mean I should set default language also to session? Then I can access it wherever I want...

When I think about it I need to use language only in models, not in controllers

general started a new conversation Constructor In Method

Hi guys I'm new to laravel som maybe dummy question. In my base controller I have variable with language.

public function __construct()
    {
        $this->lang = Session::get('language', Config::get('app.locale'));
    }

How can I access this variable in models?

15 May
3 years ago

general left a reply on Request Validation Error

I solved it... Problem was I had checkbox and also hidden input with same name of checkbox. In hidden input was Old value. When I removed this hidden input everything works. Anyway thank you @StefanoRuth

general left a reply on Request Validation Error

Laravel: 5.0.35 "laravelcollective/html": "~5.0",

in FormBuilder.php line 229 at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 43 at PhpEngine->evaluatePath('/home/vagrant/Code/Laravel/storage/framework/views/e7bc06d2ee9e8f4c73d97b679c8992f1', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in CompilerEngine.php line 57 at CompilerEngine->get('/home/vagrant/Code/Laravel/resources/views/admin/user/create.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in View.php line 142 at View->getContents() in View.php line 111 at View->renderContents() in View.php line 80 at View->render() in Response.php line 44 at Response->setContent(object(View)) in Response.php line 202 at Response->__construct(object(View)) in Router.php line 1198 at Router->prepareResponse(object(Request), object(View)) in Router.php line 702 at Router->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in RedirectIfNotAdmin.php line 40 at RedirectIfNotAdmin->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in RedirectIfNotModerator.php line 38 at RedirectIfNotModerator->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101 at Pipeline->then(object(Closure)) in Router.php line 703 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 670 at Router->dispatchToRoute(object(Request)) in Router.php line 628 at Router->dispatch(object(Request)) in Kernel.php line 214 at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in VerifyCsrfToken.php line 43 at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17 at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in ShareErrorsFromSession.php line 55 at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in StartSession.php line 61 at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 40 at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 42 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101 at Pipeline->then(object(Closure)) in Kernel.php line 115 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84 at Kernel->handle(object(Request)) in index.php line 53

general left a reply on Request Validation Error

no I get same error...

general left a reply on Request Validation Error

@StefanoRuth oh sorry no then it works!

general left a reply on Request Validation Error

@StefanoRuth the same error... Hm maybe something is wrong in blade form.

{!! Form::open(['action' => 'Admin\[email protected]', 'class' => 'main-form', 'files' => true]) !!}

{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Meno']) !!}

general started a new conversation Request Validation Error

Hi

I have some problem with request validator.

It throw this error: ErrorException in FormBuilder.php line 229: Illegal string offset 'name'

My rules:

public function rules()
{
$rulesDefault = [
            'name'              => 'required|min:3|max:255',
            'surname'           => 'required|min:3|max:255',
            'role_id'           => 'required',
            'profileValidStart' => 'date',
            'profileValidEnd'   => 'date',
            'picture'           => 'image',
            'zip'               => 'integer',
            'billingIco'        => 'integer',
            'billingZip'        => 'integer',
            'birthdate'         => 'date',
        ];

        return $rulesDefault;
}

When I remove rules for NAME, there is problem with SURNAME etc... I tried to dump type of $rulesDefault and it is array so I don't understand, where can be problem...

13 May
3 years ago

general left a reply on Form::select Default

@Prez still the same... Maybe there is some javascript problem because I use there selectpicker

general left a reply on Form::select Default

@tomo_pongrac now it works ok but when I edit form there is still default value=0

general started a new conversation Form::select Default

Hi

i'm new to laravel so maybe dummy question. In my blade I generate select with 31 days.

{!! Form::select('birthdate', $days, null, ['class' => 'selectpicker', 'data-width' => '100%']) !!}

when I dump $days it looks like:

array:32 [▼
  0 => "--- Deň ---"
  "01" => 1
  "02" => 2
  "03" => 3
  "04" => 4
  "05" => 5
  "06" => 6
  "07" => 7
  "08" => 8
  "09" => 9
  10 => 10
  11 => 11
  12 => 12
  13 => 13
  14 => 14
  15 => 15
  16 => 16
  17 => 17
  18 => 18
  19 => 19
  20 => 20
  21 => 21
  22 => 22
  23 => 23
  24 => 24
  25 => 25
  26 => 26
  27 => 27
  28 => 28
  29 => 29
  30 => 30
  31 => 31
]

When I open this form, 13 is selected. I don't want to have selected nothing. Why this happens?

general left a reply on Migrate:rollback Problem

Ok I found where was problem :)

FIrst I need to drop foreign keys. Then I can drop tables. Now everything works :)

Schema::table('users', function(Blueprint $table)
        {
            $table->dropForeign('users_role_id_foreign');
        });

        Schema::drop('roles');

general left a reply on Migrate:rollback Problem

Ok I found what was the problem. I have migrations also for foreign keys and there were duplicate for drop table. Now it throws another error with foreign keys:

[Illuminate\Database\QueryException]                                                                                                    
  SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop   
  table `roles`)      

general left a reply on Migrate:rollback Problem

Is this code correct?

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roles', function(Blueprint $table)
        {
            $table->engine = 'InnoDB';

            $table->increments('id');
            $table->string('title');
            $table->string('titleURL')->unique();
            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('roles');
    }

}

general started a new conversation Migrate:rollback Problem

Hi

I have following problem when I tried to run migrate:rollback it throws this error:

[ErrorException] Argument 2 passed to Illuminate\Database\Schema\Builder::table() must be an instance of Closure, none given, called in /Users/general/Documents/Projec ts/Laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.p hp on line 210 and defined

Other migrate functions works correctly. Can you help me what's the problem?

20 Aug
3 years ago
19 Aug
3 years ago

general left a reply on Relationship Between Users And Roles

@bimalshah72 one more question :)

I have created middleware:

public function handle($request, Closure $next)
    {
        if(!$this->auth->guest())
        {
            if($request->user()->hasRole('moderator') OR $request->user()->hasRole('admin')) {
                return $next($request);
            }
        }

        return redirect('admin/auth/login');
    }

hasRole:

public function hasRole($title)
    {
        if(!is_null($title))
        {
            if ($this->role->titleURL == $title) return true;
        }

        return false;
    }

titleURL is admin/moderator/user

general left a reply on Relationship Between Users And Roles

@bimalshah72 thank you very much this works! @thomaskim you didn't write about foreign key, this was the reason why it didn't work :)

general left a reply on Relationship Between Users And Roles

@thomaskim I know my english isn't best but like I said I created role_id column, used your code but still get error...

general left a reply on Relationship Between Users And Roles

@thomaskim still get same error... I understand my first version but don't understand your version because there is no specified role_id column from users table anywhere in method...

general left a reply on Relationship Between Users And Roles

@thomaskim still get some error from blade. Trying to get property of non-object

I think there is problem with this:

$users = User::with('roles')->get();

why with('roles') ???

general left a reply on Relationship Between Users And Roles

@thomaskim now I get some error...

ErrorException in User.php line 366: Missing argument 1 for App\User::role_id()

public function role_id($user_id)
    {
        if(!is_null($user_id))
        {
            return DB::table('role_user')->where('user_id', '=', $user_id)->first()->role_id;
        }

        return null;
    }

used in controller:

$roleActive = $user->role_id($id);

general started a new conversation Relationship Between Users And Roles

Hi guys

I finally managed to make middleware and login. Now I want to show all users from DB and show their roles (title of roles). How can I do this? I know it's possible with long query but I hope there is some better solution in Laravel :)

I have 3 tables in DB: users, roles, role_user (pivot)

User model:

public function roles()
    {
        return $this->belongsToMany('App\Role');
    }

Role model:

public function users()
    {
        return $this->hasMany('App\User');
    }

How can I show user's role in blade? BTW: every user can have only one role...

18 Aug
3 years ago

general left a reply on Terminal - Php Artisan Stopped Working

Oh yes I had error in my code but I didn't know it can cause some problems in Terminal... Thx @mikebronner I'm new in laravel :)

general started a new conversation Terminal - Php Artisan Stopped Working

Good evening

i'm using terminal on OSX. Everything worked fine until I get some error after php artisan migrate. Now when I write php artisan nothing happen. Any error, nothing. In terminal header I see SITE NAME -- bash --

general left a reply on Variable In Blade Form Label

@mikebronner thank you... such a stupid mistake :)

general started a new conversation Variable In Blade Form Label

Hi

I have following problem. In my form I have label but it's different for create and edit method so I pass variable in my @include. My code:

{!! Form::label('password', '$passwordText', ['class' => 'col-sm-3 control-label']) !!}

but this code return $passwordText (variable) in label, not text... How should I do this?

17 Aug
3 years ago

general left a reply on SetAttribute For Each Value

@thomaskim still not working...

In this case null value wasn't apply and for example mutator for password didn't worked also because it saved value without hash....

general started a new conversation SetAttribute For Each Value

Hi guys

I tried to setAttribute global for each attribute. I created BaseModel which extend Model and created there mutator:

public function setAttribute($property, $value) {
        $this->$property = empty($value) ? null : $value;
    }

It works fine but the values I filled in my form are now blank. Blank values from form are NULL so this is correct. Why it leave filled inputs blank?

general left a reply on Combine Mutators

Ok I found solution:

public function setBirthdateAttribute($value)
    {
        $this->attributes['birthdate'] = Input::get('birthdateYear')."-".Input::get('birthdateMonth')."-".$value;
    }

Other attributes in mutator are accesible only by Input::get...

general left a reply on Combine Mutators

It looks ok @zachleigh

["birthdate"]=> string(2) "01" ["birthdateMonth"]=> string(2) "01" ["birthdateYear"]=> string(4) "1990"

16 Aug
3 years ago

general left a reply on Combine Mutators

@zachleigh Undefined index: birthdateYear

general started a new conversation Combine Mutators

Hi everybody

is it possible to combine mutators?

My example: I have form, where are 3 selectors (day,month,year). I need to join them and create full date YYYY-mm-dd.

I tried something like this but it didn't work...

public function setBirthdateAttribute($value)
    {
        $this->attributes['birthdate'] = $this->attributes['birthdateYear']."-".$this->attributes['birthdateMonth']."-".$value;
    }

general left a reply on Validation And Redirect With Inputs

@bestmomo thank you! this is the solution :)

general left a reply on Validation And Redirect With Inputs

@ModestasV it's not working for me... My controller to create user:

''' public function store(Requests\UserRequest $request) { User::create($request->all());

    return redirect('admin/user')->withInput();
}

'''

And I removed old('keys') from form but they are blank after validation...

general left a reply on Validation And Redirect With Inputs

It's not possible to pass old values without putting value="{{ old('key') }}" to each input? In this laracast video it's possible to return with filled inputs without old('keys')

https://laracasts.com/series/laravel-5-fundamentals/episodes/12

What about select or checkboxes? How can I select old value?

general left a reply on Validation And Redirect With Inputs

@taijuten ok but when I have validation rules specified in Requests\UserRequest file how should my code looks like? I don't want to specify validation rules in controller...

general started a new conversation Validation And Redirect With Inputs

Hi guys

I'm doing user validation wit no problems but when validation fails I would like to redirect back withinput(). But where can I specify this???

This is how I save user and validate:

public function store(Requests\UserRequest $request) { User::create($request->all());

    return redirect('admin/user'));
}

In request file there is nothing about redirect...

14 Aug
3 years ago

general left a reply on Model Set Attribute For Checkbox

@helmerdavila I use carbon yet but there is problem with blank input... I want to let user leave this fields blank or filled...

general left a reply on Model Set Attribute For Checkbox

@bobbybouwmann @helmerdavila @phildawson guys and what about other inputs? I have two inputs valid_from and valid_to (both DATE). When I leave them blank I want to insert NULL value to DB (instead there is 0000-00-00 but column is nullable). When I insert some value like 1.August 2015 I need to format it before saving to DB.

But it also looks like when I post blank input then setValid_fromAttribute isn't call...

Sorry for many questions but I started with laravel only few days ago :)

general left a reply on Model Set Attribute For Checkbox

@helmerdavila your last solution is possible only in controller so I prefer hidden input with default value...

@phildawson yes this worked for me... Thank you

general left a reply on Database INT Assign To Array

@helmerdavila great! Thank you very much

general left a reply on Model Set Attribute For Checkbox

@Undutchable I tried your soultion but nothing changed...

@phildawson I read about this solutions but I think this is not correct solution :)

@bobbybouwmann this is how I save user

public function store(Requests\UserRequest $request) { User::create($request->all()); }

When I add return $request->status before User::create I get values 1 or empty