mercredi 13 avril 2022

how i can How can I redirect to the correct login page in Laravel carrying different middleware?

I made a duplicate of the auth file in the name of admin and modified some related things and everything works fine, but the problem is that when I go to the "/dashboard" link, it is redirected to "login" and I was supposed to be transferred to "dashboard/login" "I think the problem is in the Authenticate.php file, or is it something else? Is there someone who can help me and explain the solution to the problem?

enter image description here

part of admin route code

Route::group(['middleware' => ['guest:admin'], 'prefix'=>'dashboard', 'as'=>'dashboard.'],function(){
Route::get('register', [RegisteredUserController::class, 'create'])->name('register');
Route::post('register', [RegisteredUserController::class, 'store']);
Route::get('login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);
Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])->name('password.request');
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])->name('password.email');
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])->name('password.update');});


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/Yz6vm1a
via IFTTT

mardi 12 avril 2022

Method withCount does not exist

I am using laravel 5.4 so i'm trying to count number of relations between two models "Person" and "Permanance" so this is how it is called in my controller $persons = Person::all()->withCount('Permanance')->get(); and this is the error i'm getting

(1/1) BadMethodCallException

Method withCount does not exist. in Macroable.php line 74 at Collection->__call('withCount', array('Permanance'))in PermanancesController.php line 41



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/YtQafRv
via IFTTT

lundi 11 avril 2022

How to add number_format decimal in laravel in html view?

does anyone know how to add the decimal number_format here?, I don't use the blade from Laravel but I route the view directly to html... so if I add the number_format attribute, I'm confused ;(

<tr dir-paginate="income in incomes | filter:searchText | itemsPerPage:20" total-items="totalItems">
                            <td></td>
                            <td></td>
                            <td>Rp.</td>
                            <td></td>
                            <td></td>
                            <td>
                                <a ng-show="income.incomeImage != ''" target="_blank" href="index.php/incomes/download/"><button type="button" class="btn btn-success btn-circle" title="" tooltip><i class="fa fa-cloud-download"></i></button></a>
                                <button ng-show="$root.can('Incomes.editIncome')" ng-click="edit(income.id)" type="button" class="btn btn-info btn-circle" title="" tooltip><i class="fa fa-pencil"></i></button>
                                <button ng-show="$root.can('Incomes.delIncome')" ng-click="remove(income,$index)" type="button" class="btn btn-danger btn-circle" title="" tooltip><i class="fa fa-trash-o"></i></button>
                            </td>
                        </tr>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/I34BAcu
via IFTTT

samedi 9 avril 2022

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'asdf' for key 'user_username_unique' (SQL: update `user` set `username` = asdf

This works on create/store but not on edit/update. I want the user to be updated and the data already exists in the database, the validation error appears. like this in the user store, I added the data, and it worked, even if there was already the same data then a validation error appeared, but in a different update if I update only the address then the old username data is still used and if I change the username it also works but it doesn't if I replace the username with an existing username the validation error does not appear and instead displays the following error. please help me i am still a student!

Error

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'asdf' for key 'user_username_unique' (SQL: update `user` set `username` = asdf, `password` = $2y$10$BYdDToN5jCCuRLdZx70YA.BFgyVIWulL8n/bv5C3VxOVCw6WBN.kO, `kota_id` = 1505, `kecamatan_id` = 1505013, `desa_id` = 1505013004, `user`.`updated_at` = 2022-04-09 14:25:03 where `id` = 4)

User Migration

Schema::create('user', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('nik')->unique()->nullable();
                $table->string('nama')->nullable();
                $table->string('telp')->unique()->nullable();
                $table->string('email')->unique();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('foto')->nullable();
                $table->string('username')->unique();
                $table->string('password');
                $table->enum('level', ['user','admin'])->default('user');
                $table->unsignedBigInteger('provinsi_id')->nullable();
                $table->unsignedBigInteger('kota_id')->nullable();
                $table->unsignedBigInteger('kecamatan_id')->nullable();
                $table->unsignedBigInteger('desa_id')->nullable();
                $table->text('alamat')->nullable();
                $table->rememberToken();
                $table->timestamps();
            });

User Controller Store

  public function store(Request $request)
    {
           $validasi = $request->validate([
               'username' => ['required', 'string', 'min:3', 'max:30', 'unique:user'],
               'email' => ['required', 'email', 'string', 'max:255', 'unique:user'],
               'password' => ['required', 'string', 'min:8'],
               'nama' => ['required', 'string', 'min:3', 'max:50'],
               'nik' => ['required', 'string', 'min:16', 'max:16', 'unique:user'],
               'telp' => ['required', 'string', 'min:12', 'max:13', 'unique:user'],
               'provinsi_id' => ['required'],
               'kota_id' => ['required'],
               'kecamatan_id' => ['required'],
               'desa_id' => ['required'],
               'foto' => ['mimes:jpeg,jpg,png'],
               'level' => ['required'],
               'alamat' => ['required'],
           ]);
           $validasi['password'] = Hash::make('password');
           $create = User::create($validasi);
           if($request->hasFile('foto')){
               $request->file('foto')->move('images/',$request->file('foto')->getClientOriginalName());
               $create->foto = $request->file('foto')->getClientOriginalName();
               $create->save();
            }

           return redirect()->route('user.index');
    }

User Controller Update

public function update(Request $request, $id)
        {
            $user = User::find($id);
            $validasi = $request->validate([
                'username' => ['required', 'string', 'min:3', 'max:30', 'unique:user,id'],
                'email' => ['required', 'email', 'string', 'max:255', 'unique:user,id'],
                'password' => ['required', 'string', 'min:8', 'max:20'],
                'nama' => ['required', 'string', 'min:3', 'max:50'],
                'nik' => ['required', 'string', 'min:16', 'max:16', 'unique:user,id'],
                'telp' => ['required', 'string', 'min:12', 'max:13', 'unique:user,id'],
                'provinsi_id' => ['required'],
                'kota_id' => ['required'],
                'kecamatan_id' => ['required'],
                'desa_id' => ['required'],
                'foto' => ['mimes:jpeg,jpg,png'],
                'level' => ['required'],
                'alamat' => ['required'],
            ]);
            $validasi['password'] = Hash::make('password');
            $user->update($validasi);
            if($request->hasFile('foto')){
                $request->file('foto')->move('images/',$request->file('foto')->getClientOriginalName());
                $user->foto = $request->file('foto')->getClientOriginalName();
                $user->save();
             }
    
            return redirect()->route('user.index');
        }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/zSwbHdA
via IFTTT

vendredi 8 avril 2022

Laravel Http Client - How to upload file to linkedin Assets API

I wanted to upload a file using Laravel HTTP Client, but I'm not able to understand how to work or attach media to LinkedIn. And moreover, LinkedIn API does not even give back any response after upload this becomes even harder for me to figure out where I went wrong.

But LinkedIn documentation shows an example using the curl command which I successfully achieved to upload a file and even in the postman I was able to do so by choosing the PUT method and body as a binary file.

Below is LinkedIn Doc under the "Upload the Image" section an example is given for bash.

https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/vector-asset-api?tabs=http#upload-the-image

Below is the small piece of code I'm trying to achieve upload functionality

   Http::attach('file', file_get_contents($request->file('file')), 'perfidious.jpg')
            ->withHeaders([
                'Authorization' => 'Bearer ' . $oauth2_token,
                'Content-Type' => $file->getMimeType(),
            ])->put('https://api.linkedin.com/mediaUpload/C4E22AQFyx5-WPFqU4w/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJDUuJEebKdjgAAAYAIF2PvtGz3bIfDzdyIAomflRbj4jD-Z1lcfP-7NQ&app=201094746&sync=1&v=beta&ut=1S4fxf2p45tWc1')
            ->json();

What I know from Laravel Docs is "file_get_contents" method reads file data as a string.

https://laravel.com/docs/9.x/http-client

Please, anyone, help me guide on how to do it as I have very minimal knowledge in PHP and Laravel. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/pbUhwtS
via IFTTT

jeudi 7 avril 2022

in array how to pass query for perfect result

 $arr = str_replace('"','', $request->course_id);
  $arr = str_replace('"','', $request->stream_id);
    $arr = str_replace('[','', $arr);
    $arr = str_replace(']','', $arr);
    $arr = explode(',',$arr);
      $a = array(College::whereIn('course_id',$arr)->get());
     $b = array(College::whereIn('stream_id',$arr)->get());
    
    $result =  array_merge($arr,$a, $b );
     return $result;

enter image description here

This is code i done, but not get exact result which i want, i want to filter like when pass id course id 1 and value BCA then show BCA college list, college is 1 table and course is another table and common id in both table is course id, what is exact problem in this code



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/pdgxoAO
via IFTTT

mercredi 6 avril 2022

cannot run commands in tinkerwell over ssh connection (laravel)

Tinker works just fine when I am ssh'd into my box, but I cannot get it to work in tinkerwell.

I'm trying to connect to my local vagrant box with tinkerwell. It is a vagrant box running in windows: ubuntu 20, laravel 5.7, php7.3.33. Tinkerwell 2.25 in Windows 10. I can connect over ssh, but it errors out whenever I run any command:

enter image description here

In Shell.php line 79: Argument 1 passed to _PhpScoperc223a629f245\Psy\Shell::add() must be an ins tance of _PhpScoperc223a629f245\Symfony\Component\Console\Command\Command, instance of Psy\Command\ParseCommand given, called in phar:///tmp/vagrant_t
inker.phar/vendor/symfony/console/Application.php on line 316

I get the same error whenever I try to run any command. On google I found a thread where someone had the same issue, except they were not connecting over ssh, they were on a mac, and the thread had no resolution in it (https://github.com/beyondcode/tinkerwell-community/issues/215).

I have checked that the correct version of php is in my $PATH, so the default path of php for the php executable that tinkerwell picks seems correct. I have also tried specifying /usr/bin/php but it doesn't change anything.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/Qkpzne4
via IFTTT