amit123

Experience

650

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 0 Lessons Completed
  • 0 Favorites

14th November, 2017

amit123 left a reply on Laravel Validation Rules: Ignore Unique Doesn't Is Completely Ignored. • 1 week ago

Forgot to tell but name is actually my PK and my table doesn't have any column 'id'. The Docs say that I have to specify 'name' as forth parameter if my PK isn't ID but still something is wrong.

amit123 started a new conversation Laravel Validation Rules: Ignore Unique Doesn't Is Completely Ignored. • 1 week ago

Hey, I have some trouble with the ignore unique rule.

public function rules()
{

    $user = $this->route()->parameter('user');

    //dd($user) // returns the user when updating || returns null when creating

    return [

        'name' => [

            //the ignore unique is ignored when updating

    //trying to get Trying to get property of  non-object when creating

            Rule::unique('users')->ignore($user->id, 'name'),


            //SQL Exception: Duplicate entry for PK when creating 

    // ignore unique is ignored when updating

            (isset($user) && $user)?Rule::unique('users')->ignore($user->id, 'name'):null,


            // trying to get Trying to get property of non-object when creating 

    //ignore unique is ignored when updating 

              'unique:users,name,'.$user->id.',name'

        ],

    ];

}

I tried some ways to use it, but it never work. I wrote for every way I tried what happens.

Hope you can tell me whats Wrong thanks Amit

13th November, 2017

amit123 left a reply on Useful Routing In Laravel • 1 week ago

Will watch both videos at home. right now it's not possible. another question to the controllers: in my DB I still have only one users Table with a column type that can have values 'customer' and 'employee'

It is still possible, if I have two controllers?

amit123 left a reply on Useful Routing In Laravel • 1 week ago

Route::get('/', function () {

return redirect('/users');

});

Route::get('/users/{user}/password', '[email protected]');

Route::get('/users/{user}/delete', '[email protected]');

Route::get('/users/{user}/new-password', '[email protected]');

Route::post('/users/{user}/new-password', '[email protected]');

Route::get('/users/create/customer', '[email protected]');

Route::get('/users/create/employee', '[email protected]');

Route::resource('/users', 'UsersController');

// added now

Route::post('users/{user}', '[email protected]');

amit123 started a new conversation Useful Routing In Laravel • 1 week ago

hey guys,

I am Working on my first Laravel project and I am also new to routing and controllers at all.

Well, at the beginning I had a UsersController withe the functions create, store, update and so on and in http/requests/ a UserRequest. All users were by default customers. Then I had to do the same for users that were employees. First I used the same store and update function for both of them and put a lot if-Conditions in those functions for almost any input.

What I actually had to do is creating customerRequest and EmployeeRequest instead of one UserRequest and having in my Userscontrollers the functions StoreCustomer and StoreEmployee instead of just store.

I tried adding this line to the routes: Route::post('users/{user}', '[email protected]');

and I get, when submitting : BadMethodCallException Method [store] does not exist.

But how do I tell laravel which function it has to take?

amit123 left a reply on Ignore Unique Rule When Updating User • 1 week ago

The syntax changed since Laravel 5.1. and I'm using laravel 5.5.

https://laravel.com/docs/5.5/validation#rule-unique

amit123 left a reply on Ignore Unique Rule When Updating User • 1 week ago

Thats What the Documentation says about non-conventional PK:

If your table uses a primary key column name other than id, you may specify it as the fourth parameter:

'email' => 'unique:users,email_address,'.$user->id.',user_id'

https://laravel.com/docs/5.1/validation#rule-unique

I tried dd($request) on the first line and request was empty. My IDE also tells me, that PHP Documentation comments are missing for a Parameter in this function. Since I work with laravel for only one Month everything should be up to date, so I guess I'm actually not allowed to pass any parameter to that function.

Am I right?

7th November, 2017

amit123 started a new conversation Ignore Unique Rule When Updating User • 2 weeks ago

hello, name is my pk. when I update a user I want it to be ignored.

I tried to do exactly this but it doesn't work. on sumbit I see a blanco page and after refreshing again nothing changes. What I am doing wrong?

use Illuminate\Foundation\Http\FormRequest;

use App\User;

class UserRequest extends FormRequest

{

public function rules(UserRequest $request)

{

    $user=User::where('name', $request->name);

    return [

        'name' => 'required|alpha_num|unique:users,name,' .$user->id.',name',

    ];

}

}

thanks Amit

amit123 left a reply on Regex In Validator Rules • 2 weeks ago

alpha_num works. I actually also tried:

'regex:/^[a-zA-Z0-9]+$/',

and many other versions. now I have many invalid entries in my database and i can't delete them because of "safe mode"

amit123 started a new conversation Regex In Validator Rules • 2 weeks ago

hello,

Something is wrong with my regex in Laravel a username should only include uppercase letters, lowercase letters and numbers.

public function rules()

{

    return [

        'name' => [

                    'required',

                    'unique:users,name',

                    'min:10',

                    'regex:/[a-z{1}A-Z{1}0-9{1}]+/',

                 ]

    ];

}

According to this site it actually should work: https://regexr.com/

hope you guys could help me again

thanks Amit

amit123 left a reply on Checking If Username Is Already Taken • 2 weeks ago

works perfect. Thanks a lot.

amit123 started a new conversation Checking If Username Is Already Taken • 2 weeks ago

Hello,

in my Users table in my DB the column name is defined as PK. Now I have a form to create new user. If the name already exists the sql throws an error on submit.

Now I would like to catch it and stay in the Form and give the user an error message so he can immidiatly try another username.

could you give me an advice please how to do this?

Thanks Amit

amit123 left a reply on Compound If Conditions • 2 weeks ago

I tried to abstract the example to avoid posting long code statements in here. The code looks actually looks like this:

if ($user->uid == 25401 && isset($input['writers']) && $input['writers'] && ! $user->hasWritePrivileges()) {

        GroupUser::create([

            'group_name' => 'writers',

            'user_name' => $user->name

        ]);

    } elseif ($user->uid == 85454 && isset($input['writers']) && ! $input['writers'] && $user->hasWritePrivileges()) {

        GroupUser::where('user_name', $user->name)->where('group_name', 'writers')->delete();

    }

The function hasWritePrivileges() is defined in the User Model

public function hasWritePrivileges(){

    return !! $this->groups()->where('name', 'writers')->count();

}

6th November, 2017

amit123 left a reply on Compound If Conditions • 2 weeks ago

I have a formular with a checkbox. if it is checked user should get some privileges and if it is unchecked it shouldn't have them

when updating I have to relevant cases case1: user does not have privileges but should get some --> create() case2: user has privileges but they should be removed--> delete()

amit123 started a new conversation Compound If Conditions • 2 weeks ago

In my controller I try to create some logic for updating my database.

if( $request==1 && is_in_database()==false){ //create }elseif( $request=0 && is_in_database()==true){ //delete }

Is there any way to do this? It never executes the statesments because a part of the condition is false.

thanks Amit

amit123 left a reply on Using Enviroment Variables In Laravel View Doesn't Work • 2 weeks ago

The reason for that phenomenon was an accessor defined by a co-worker in the User Model.

30th October, 2017

amit123 left a reply on Using Enviroment Variables In Laravel View Doesn't Work • 3 weeks ago

there is no "...". I just removed some parts that might be sensitive. so it actually should work the way I think?

thanks anyway

amit123 left a reply on Using Enviroment Variables In Laravel View Doesn't Work • 3 weeks ago

dd($user->home_directory) // "/some_path/ssss"

dd($user) //

User {#219 ▼ #primaryKey: "name" +incrementing: false #fillable: array:10 [▶] #hidden: array:1 [▶] #connection: "mysql" #table: null #keyType: "int" #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:13 [▼ "name" => "cf1arWGHz5TI" "type" => "customer" "password" => "3g17vv9V57B1" "home_directory" => "/srv/.../clients/some_path/ssss" "shell" => "/sbin/nologin" "uid" => 79594 "gid" => 95978 "is_hidden" => 0 "comment" => null "description" => null "created_at" => "2017-10-30 10:41:02" "updated_at" => "2017-10-30 14:11:23" "deleted_at" => null ] #original: array:13 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [▶] #touches: [] +timestamps: true #visible: [] #guarded: array:1 [▶] #rememberTokenName: "remember_token" #forceDeleting: false

amit123 started a new conversation Using Enviroment Variables In Laravel View Doesn't Work • 3 weeks ago

hey,

I discovered a phenomenon in Blade that I cannot explain or handle at all.

In the store function in UsersControllers I save the directory of a user. A directory typically looks like The Base Path is defined in my .env file. In config/app.php I also say : 'base_path' => env('BASE_PATH', '/srv/ftp'), And then I get it in my controller store function using config() and finally store there full path in my DB. All this actually works fine.

Now it starts getting weired. In my show view I want to get the full path back but when do {{dd($user->directory)}} // prints only {{dd($user)}} // prints an object that contains a directory attribute with the full path

can you explain me what laravel exactly does there and what I am doing wrong?

Thanks Amit

amit123 left a reply on Fit A Long String To A Table Column • 3 weeks ago

I need to wrap it.

I solved it that way: in my app.scss:

td.break-it { @include word-wrap; }

then I added Class="break-it" to my td element.

24th October, 2017

amit123 started a new conversation Fit A Long String To A Table Column • 1 month ago

Hey there,

in my view I have a table with two columns. I want to write a quiet long public key into a column using blade but it kind don't wanna fit. I was trying about php wordwarp() but it didn't work and even if it would work, then I still have to hardcode the number of chars before it automaticly breaks so if I change the size of the window it would for sure turn into a mess.

Is there any other solution?

thanks

23rd October, 2017

amit123 left a reply on Syntax In If-statement Condition • 1 month ago

got it. thanks. now the code makes sense

amit123 started a new conversation Syntax In If-statement Condition • 1 month ago

I am new to laravel and php and I am working on a project that someone already started implementing before.

if ($user->uid == 1 && ! !! $user->groups->where('name', 'writers')->count()) {...}

Can you explain the syntax "! !!" in The condition to me? Tried to google but just got general answers about how if-statements work in php

Thanks

17th October, 2017

amit123 left a reply on Storing Form Request Inputs In Multiple Tables With Different Values And Same Names • 1 month ago

the second solution worked for me. thanks

amit123 started a new conversation Storing Form Request Inputs In Multiple Tables With Different Values And Same Names • 1 month ago

hey, I'm a student and new to Laravel. As the title says I have a form that contains multiple Input fields "comment" that should be saved as an array or json in table1 in column "comment" and I have another "comment" input field that should be saved as String under table2 in column "comment. Laravel actually takes the value that belongs to table 2 and saves it in both tables.

How can I fix that?

Thanks Amit

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.