vendredi 11 novembre 2022

Can config/auth.php be made dynamic?

Can helper functions or through any other medium be used to make changes in config/auth.php? I mean can we get some data from the database through helper function or some other way and just append the data to config/auth.php.

I was trying to append the data to guards key. I made a guards table and formatted the data to the exact format of guards key of config/auth.php.

I called a helper function in config/auth.php and tried to get the data of guards but it showed a bunch of errors.



via Chebli Mohamed

jeudi 10 novembre 2022

CSRF token mismatched in laravel when i moved project to another server

enter image description here

Hii My website is not working on other server code is same into both server

1, Working server

http://programmingly.com/articles/

  • testuser@gmail.com
  • 12345678 (Working perfect)

https://www.vennocracy.com/

  • testuser@gmail.com
  • 12345678 (Not Working)

I tried ajax for that

$('#login-form').validate({
        rules: {
            email: {
                required: true,
            },
            password: {
                required: true,
            },
        },
        messages: {
            email: {
                required: 'Please enter email',
            },
            password: {
                required: 'Please enter password',
            },
        },
        submitHandler: function(form) {
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "",
                type: "POST",
                data: new FormData(form),
                dataType: 'json',
                contentType: false,
                cache: false,
                processData: false,
                beforeSend: function() {
                    $("body").append(
                        "<div class='ajax-overlay'><i class='porto-loading-icon'></i></div>"
                        );
                },
                success: function(res) {
                    $(".ajax-overlay").remove();
                    if (res.status) {
                        $('.all-error').html('');
                        $('.all-success').html('');
                        $('.all-success').html(res.message);
                        setTimeout(function() {
                            $("#loginModal").modal('hide');
                            location.reload();
                        }, 4000);
                    } else {
                        $('.all-error').html('');
                        $('.all-error').html(res.message);
                    }
                },
                error: function(data) {
                    $(".ajax-overlay").remove();
                    var errorString = '';
                    $.each(data.responseJSON.errors, function(key, value) {
                        errorString += value + '<br>';
                    });
                    $('.all-error').html('');
                    $('.all-success').html('');
                    $('.all-error').html(errorString);
                },
            });
            return false;
        }
    });


via Chebli Mohamed

mercredi 9 novembre 2022

What benefit is there in using artisan auth:clear-resets? Does it prevent certain issues or only maintains table size?

Does artisan auth:clear-resets do anything besides clearing the password_resets table? Does this affect the functionality of the password reset system?

I've been having some problems where our users trigger a password reset but as soon as they click through in the provided email they get an "invalid token" notice. I use artisan auth:clear-resets and it seems that the complaints go away...

It could be a coincidence but I was wondering if there was an underlying benefit to clearing the password_resets table that I'm unfamiliar with



via Chebli Mohamed

Laravel, download 2 files on one button click

I'm trying to make a feature where one button being clicked will access a single route and controller but the controller will sequentially download 2 files. The catch is they can't be zipped, they need to be downloaded sequentially as single files.

I've tried with this but I get an array to string conversion error.

public function fileDownload(){

    $first_file_name = 'test.xlsx';
    $first_file_path = storage_path("files/{$first_file_name}");

    $second_file_name = 'test2.xlsx';
    $second_file_path = storage_path("files/{$second_file_name}");  

    return \Response::download([$first_file_path, $second_file_path]);
}

Is there a way to do this in Laravel 5.3?



via Chebli Mohamed

how to show multiple filenames in one json format?

I'm not sure where and how I should use the for loop.

I am using Laravel v5.5. I am trying to upload multiple files on my project. I think if I can add all filenames in one json array I can show them in blade page. How can i do that?


        if(request()->hasFile('urun_resmi')) {
            $files = request()->file('urun_resmi');
            $filename = [];
            foreach ($files as $file) {
                if($file->extension() == 'pdf')
                {
                    $filename = $file->extension() . "-" . $entry->id . "-" . time() . "." . $file->extension();
                }else
                {
                    $filename = $entry->id . "-" . time() . "." . $file->extension();
                }
                $file->storeAs('urunler', $filename, 'public');
                $entry->detay()->update(['urun_resmi' => $filename]);
                
          
                if ($file->isValid()) {
                    $file->move('uploads/urunler', $filename);
                    UrunDetay::updateOrCreate(
                        ['urun_id' => $entry->id],
                        ['urun_resmi' => $filename]
                    );
                }
            }

        }


via Chebli Mohamed

mardi 8 novembre 2022

laravel log debug is not working.I checked A response is returned from the server side

laravel log debug is not working.

I create app with laravel5 and vue.js.

I send a request to the server side with vue and catch this with laravel Controller.php.

I code Log::debug to PostsController.php, but the log is not written in laravel.log.

I try use Illuminate\Support\Facades\Log; and use Log; , but both are not working.

Do you find anything wrong with my code?

Thank you for your help.

// web.php

Route::get('/posts/items', 'PostsController@items');
PostsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Model\Post;
use App\Model\Item;
// use Log;
use Illuminate\Support\Facades\Log;

use App\Http\Resources\Post as PostResource;
use App\Http\Resources\Item as ItemResource;

class PostsController extends Controller
{

    public function items(Request $request)
    {
        Log::info('kita');
        Log::debug('kurukao');
        logger()->debug('debug');

        $post_id = $request->input('post_id');
        return $post_id;
    }

//vue


    methods: {
      mouseenter(id) {
        this.itemId = id;
      },
      mouseleave(id) {
        this.itemId = null;
      },
      getItems() {
        axios.get("/posts/items", {
            post_id: this.$route.params.id
        })
        .then((res) => {
        //   console.log(res.data)
          console.log('ok')
          this.postDataList = res.data.data;
        //   console.log(this.postDataList)
          if(this.postDataList != null){
            this.itemDataList = this.postDataList[0]['items'];
          }
        });
      },


via Chebli Mohamed

I type php artisan make:migartion ... and php artisan migrate, but table was not created

I create laravel5,mysql8 environment with docker-compose. I create post table with laravel migration. but I entered mysql container and checked if the table was created, but the table was not created.

I type php artisan make:migration create_posts_table and It works. Then, I did the following. enter image description here

as pictured, table is not exist. why is this? Thank you for your help.

enter image description here

enter image description here



via Chebli Mohamed