mercredi 6 avril 2022

Sail up for Laravel project does not work

I've cloned a repository from GitHub, and when I try to sail up, I get this message: /usr/bin/env: ‘sh\r’: No such file or directory.

The following is from the laravel website which I believe is the solution to my problem:

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php81-composer:latest \
    composer install --ignore-platform-reqs

The source of the above code: https://laravel.com/docs/8.x/sail#installing-composer-dependencies-for-existing-projects

I've done docker run laravelsail/php81-composer:latest which gives me an error.

Can you please guide me to get my sail up working?

Thanks.



via Chebli Mohamed

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 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, and the thread had no resolution in it (https://github.com/beyondcode/tinkerwell-community/issues/215). I have checked that I only have a single instance of php installed, and its in my $PATH, so the default path of php for the php executable that tinkerwell picks seems correct.



via Chebli Mohamed

mardi 5 avril 2022

laravel - can not change base URL in Docker + Laravel PHP + Nginx

I try to migrate my backend website (containing API service to mobile apps) from LAMP into docker platform. currently this docker split into 3 parts (Laravel App, database & nginx). sofar, the website launch successfully without error.

However, I need base URL to be like below:

http://backend.example.com/public/

so, if i want to login, url will be http://backend.example.com/public/login, also API url with above format like http://backend.example.com/public/api/v1

What I have tried:

  1. Set APP_URL value in .env to http://backend.example.com/public/
  2. Set below setting in config/app.php to:
'url' => env('APP_URL', 'https://backend.example.com/public'),
'asset_url' => env('ASSET_URL', null)
  1. run php artisan route:clear and php artisan migrate

but still not successfull, evertime i launch web browser, url still stuck to:

http://backend.example.com/

http://backend.example.com/login/

http://backend.example.com/api/v1/

etc

any idea to overcome above problem?

===Additional Note

  1. nginx conf for nginx docker:
server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}
  1. original base URL in LAMP are http://backend.example.com/public/, in original i'm using LAMP (Apache+PHP+MySQL) but in current Docker I'm using (Nginx + MySQL + php:7.4-fpm), however because an error, i change something so original base url cannot be achieved anymore...

  2. Reference of This Migration can be found here.



via Chebli Mohamed

How to pass many records through Form in Laravel 8?

The essence of the problem is that I started to learn Laravel and I can not find information on how to pass many fields through the form, followed by validation. Form example:

How to do it right?

`<form class="mt-5" method="post" enctype="multipart/form-data"
    @isset($word)
        action=""
    @else
        action=""
    @endisset
@csrf
@isset($word)
    @method('PUT')
@endisset
<table class="table table-responsive-md">
    <tbody>
        <tr>
            <th>ID</th>
            <th>English</th>
            <th>Transcription</th>
            <th>Russian</th>
            <th>Ukrainian</th>
            <th>Module</th>
            <th>Action</th>
         </tr>
         @for($i = 1; $i < 3; $i++)
            <tr>
                <td></td>
                <td><input type="text" name="eng[]" class="form-control"
                                           value=""></td>
                <td><input type="text" name="transaction[]" class="form-control"
                                           value=""></td>
                <td><input type="text" name="ru[]" class="form-control"
                                           value=""></td>
                <td><input type="text" name="uk[]" class="form-control"
                                           value=""></td>
                <td><input type="text" name="category_id[]" class="form-control"
                                           value=""></td>
                <td></td>
             </tr>
           @endfor
       </tbody>
    </table>
    <a class="btn btn-secondary mt-4" href="">Back</a>
    <button class="btn btn-success  mt-4">Save</button>
</form>`

The output is like this, but I know for sure that this is not right.

^ array:6 [▼ "_token" => "Olp8kMQIFoDP9OOvV5YRihcV3FpKIHofxfYk8W7M" "eng" => array:2 [▶] "transaction" => array:2 [▶] "ru" => array:2 [▼ 1 => "www" 2 => "qqq" ] "uk" => array:2 [▶] "category_id" => array:2 [▶] ]



via Chebli Mohamed

lundi 4 avril 2022

i can´t save my image or my file when upload it

My problem it´s, mi folder it´s created but my file it´s not uploaded. i have this code:

if(isset($request->file_job)){
            $pathFolder = storage_path('app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea);
            $filePath = 'app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea;
           
            if(!\File::exists($pathFolder)) {
                \File::makeDirectory($pathFolder, 0755, true, true);
            }
            
            \Storage::disk('local')->putFileAs($filePath, $request->file_job, ($request->file_job)->getClientOriginalName());
        }

this code generate all my folder structure but not save my file (image) i don´t know that i´m doing wrong.

Thanks for help me



via Chebli Mohamed

Change .htaccess directory in laravel 5.6

Hell folks,

In my project the .htaccess file is placed in the project root directory.

I want it placed in some other directory say '/public/setupfiles' and the project should be able to access it.

Is it possible? if yes thn how?



via Chebli Mohamed

dimanche 3 avril 2022

Laravel 5.6 ajax request internal server error

Hello i'm developing like disliked system based on https://www.itsolutionstuff.com/post/php-laravel-5-like-dislike-system-tutorialexample.html

but the ajax function throwing internal server error

this is my controller

public function ajaxRequest(Request $request)
    {
        $post = Post::find($request->id);
        $response = auth()->user()->toggleLiked($post);

        return response()->json(['success' => $response]);
    }

and this is my ajax request:

<script type="text/javascript">
    $(document).ready(function() {


        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });


        $('i.glyphicon-thumbs-up, i.glyphicon-thumbs-down').click(function(){
            var id = $(this).parents(".panel").data('id');
            var c = $('#'+this.id+'-bs3').html();
            var cObjId = this.id;
            var cObj = $(this);


            $.ajax({
               type:'POST',
               url:'/ajaxRequest',
               data:{id:id},
               success:function(data){
                  if(jQuery.isEmptyObject(data.success.attached)){
                    $('#'+cObjId+'-bs3').html(parseInt(c)-1);
                    $(cObj).removeClass("like-post");
                  }else{
                    $('#'+cObjId+'-bs3').html(parseInt(c)+1);
                    $(cObj).addClass("like-post");
                  }
               }
            });


        });


        $(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
            event.preventDefault();
            $(this).ekkoLightbox();
        });
    });
</script>

this is the form for clicking the likes

    <span class="pull-right">
       <span class="like-btn">
       <i id="like" class="glyphicon glyphicon-thumbs-up "></i>
     
       <div id="like-bs3"></div>
     <span>
   </span>

what i have done is changing the routes in case it's missing something, but still throwing the same error, what should i do?



via Chebli Mohamed