lundi 1 juin 2020

How can i make a edit page?

I am trying to make an edit page like in this video: https://www.youtube.com/watch?v=PAP8IS_ak6w But i am trying use and not , but is not working, but my create page is working normal and is basically the same.

Is showing error 404|NOT FOUND

Here is my code:

edit.blade.php:

@extends('layouts.index')
@section('content')
<div class="head">
    <div class="m-auto center" style="width: 480px;">

        @if ($errors->any())

            @foreach ($errors->all() as $error)

                <div style="height: 550px; border-radius: 35px; background-color: #F0EFEF">


                    <div class="d-flex justify-content-center ">
                        <h4 class="font py-5" style="color: #7B7B7B; ">Edit a new Product</h4>
                    </div>
                    <div class="d-flx justify-content-center">
                        <div style="margin-left: 60px">
                            <p class="font text-weight-light text-danger"> </p></div>

                        <form action="submit" method="post">
                            
                            



                            <div class="d-flex justify-content-center ">
                                <input class="w-75 shadow py-2 font pl-2" type="text" name="name" maxlength="64"
                                       placeholder="Product Name"
                                       style="border:none; border-radius: 4px" required></div>


                            <div class="d-flex mt-4 justify-content-center">
                    <textarea class=" w-75 pt-2 shadow font pl-2" type="text" name="description"
                              placeholder="Description"
                              style="border:none;  border-radius: 4px; height: 100px; resize: none"
                              required></textarea>
                            </div>


                            <div class="row mt-4 ">
                                <select class="form-control border-0 shadow mt-2" id="exampleFormControlSelect1"
                                        style="width: 150px; margin-left: 75px"
                                        name="category">
                                    <option>Classic</option>
                                    <option>Sports car</option>
                                    <option>Luxury vehicle</option>
                                    <option>Van</option>
                                    <option>Truck</option>
                                </select>
                                <div style="margin-left: 37px">
                                    <p class="font m-3" style="color: #7B7B7B;">Price</p></div>

                                <input class="shadow font p-1 text-center mt-2" type="number" min="0.01" step="0.01"
                                       max="2500.00" placeholder="0.00" name="price"
                                       style="border:none; border-radius: 4px; width: 100px; height: 40px;"
                                       required></div>


                            <div class="d-flex justify-content-center mt-5">

                                <div class="  m-3">
                                    <a href="/your"><p style="color: dimgray; "><strong>GO BACK</strong></p></a>
                                </div>
                                <div class="mt-2 ml-5">
                                    <button type="submit"
                                            class="btn  font  rounded-pill text-white font-weight-bold "
                                            style="background-color: #28AD47; width: 178px">Save
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
    </div>

    @endforeach

    @else

        <div style="height: 550px; border-radius: 35px; background-color: #F0EFEF">


            <div class="d-flex justify-content-center ">
                <h4 class="font py-5" style="color: #7B7B7B">Edit a new Product</h4>
            </div>

            <form action="submit" method="post">
                
                



                <div class="d-flex justify-content-center ">
                    <input class="w-75 shadow py-2 font pl-2" type="text" name="name" maxlength="64"
                           placeholder="Product Name"
                           style="border:none; border-radius: 4px" required></div>


                <div class="d-flex mt-4 justify-content-center">
                    <textarea class=" w-75 pt-2 shadow font pl-2" type="text" name="description"
                              placeholder="Description"
                              style="border:none;  border-radius: 4px; height: 100px; resize: none"
                              required></textarea>
                </div>


                <div class="row mt-4 ">
                    <select class="form-control border-0 shadow mt-2" id="exampleFormControlSelect1"
                            style="width: 150px; margin-left: 75px"
                            name="category">
                        <option>Classic</option>
                        <option>Sports car</option>
                        <option>Luxury vehicle</option>
                        <option>Van</option>
                        <option>Truck</option>
                    </select>
                    <div style="margin-left: 37px">
                        <p class="font m-3" style="color: #7B7B7B;">Price</p></div>

                    <input class="shadow font p-1 text-center mt-2" type="number" min="0.01" step="0.01"
                           max="2500.00" placeholder="0.00" name="price"
                           style="border:none; border-radius: 4px; width: 100px; height: 40px;"
                           required></div>


                <div class="d-flex justify-content-center " style="margin-top: 70px">

                    <div class="  m-3">
                        <a href="/your"><p style="color: dimgray; "><strong>GO BACK</strong></p></a>
                    </div>
                    <div class="mt-2 ml-5">
                        <button type="submit" name="submit"
                                class="btn  font  rounded-pill text-white font-weight-bold "
                                style="background-color: #28AD47; width: 178px">Save
                        </button>
                    </div>
                </div>
            </form>
        </div>
</div>
@endif




@endsection

ProductController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;


class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()

    {
        $products = Product::orderBy('name')->paginate(10);
        return view('show')->with('products', $products);


    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */



    public function store(Request $request)
    {

        $this->validate($request, [
            'name' =>'required | unique:product|max:64',
            'description' => 'required',
            'category' => 'required',
            'price' => 'required',
        ]);


        print_r($request->input());
        $product = new Product;
        $product->name = $request->name;
        $product->description = $request->description;
        $product->category = $request->category;
        $product->price = $request->price;
        $product->user_id = auth()->user()->id;
        echo $product->save();

        return redirect('/home');
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $product = Product::find($id);
        return view('your')->with('product', $product);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {

        $product = Product::find($id);
        return view('edit')->with('product', $product);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' =>'required | unique:product|max:64',
            'description' => 'required',
            'category' => 'required',
            'price' => 'required',
        ]);


        print_r($request->input());
        $product = Post::find($id);
        $product->name = $request->input('name');
        $product->description = $request->input('description');
        $product->category = $request->input('category');
        $product->price = $request->input('price');
        echo $product->save();

        return redirect('/your');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

web.php:

  <?php

use Illuminate\Support\Facades\Route;



Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::resource('home', 'ProductController');

Route::get('profile', 'UserController@profile')->middleware('auth');

Route::post('profile', 'UserController@update_avatar')->name('profile');

Route::view('create', 'create')->middleware('auth');

Route::post('submit', 'ProductController@store');

Route::post('submit', 'ProductController@update');

Route::get('/your', 'YourController@index');

How can I avoid the error?



via Chebli Mohamed

Laravel 5 send text file to the user

I'm new to Laravel.

I want create text file filled with the results of the database and send it to the user. I'm not finding options to not have to store the file on my server.

Thank you for your time.



via Chebli Mohamed

Proper way to configure a dockerized Laravel project with queue worker and tag with docker-compose

I am struggling a bit on how to configure a Laravel project I have configured with Gitlab pipelines for production. My project is running on Azure and I am struggling with two things.

1.- Check if queue worker is running
2.- How to push docker-compose image to container registry with tag. docker build -t tag can do it, however, it won't tag me the service that runs the queue worker.

My pipeline is

build azure:
  stage: build
  allow_failure: false
  image: docker/compose:latest
  services:
    - docker:stable-dind
  script:
    - docker login $REPO.azurecr.io -u $AZURE_USER -p $AZURE_PASSWORD
    - docker-compose -f docker-compose.build.yml down
    - docker-compose -f docker-compose.build.yml build
    - docker-compose -f docker-compose.build.yml push 

And my docker-compose

version: "3.6"
services:
  app:
    image: ${REPO}.azurecr.io/${REPO_NAME}:latest
    build:
      context: .
      dockerfile: ./setup/Dockerfile
    container_name: simple2_web
    restart: unless-stopped
    tty: true
    volumes: 
      - uploads:/var/www/simple/public/uploads
      - logos:/var/www/simple/public/logos
    networks:
      - mynet

  worker:
    image: ${REPO}.azurecr.io/${REPO_NAME}:latest
    command: ["php artisan queue:work --timeout=0"]
    depends_on: 
      - app
    networks:
      - mynet

volumes: 
  uploads:
  logos:

networks: 
  mynet:


via Chebli Mohamed

What can a hacker do with your .ENV file? [closed]

I understand most of mysql deny external connections. So, let's say my .env file is exposed and a hacker manages to get it. What can they do with its information?



via Chebli Mohamed

Laravel MSSQL Server Connection not working

Laravel version:7.13, SqlServer:2019

 SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: 
 An existing connection was forcibly closed by the remote host (SQL: select * from [users]).

Above is error message what I got.

I tried with core php and it works well.

Below is php code.

<?php

$serverName = "MYPCNAME";
$connectionInfo = array( "Database"=>"DBNAME", "UID"=>"sa", "PWD"=>'MyPassword');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
     echo "Connection established.<br />";

     if(($result = sqlsrv_query($conn,"SELECT * FROM users")) !== false){
        while( $obj = sqlsrv_fetch_object( $result )) {
              echo $obj->name.'<br />';
        }
    }

}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

?>

I think SQL Server configuration is correct. I installed php_sqlsrv, php_pdo_sqlsrv extensions and they are displayed as installed in phpinfo()

Here is my Laravel configuration.

DB_CONNECTION=sqlsrv
DB_HOST=MYPCNAME
DB_PORT=1433
DB_DATABASE=DBNAME
DB_USERNAME=sa
DB_PASSWORD=MyPassword

Following is database config file.

 'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST'),
            'port' => env('DB_PORT'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

I tried to change DB_HOST with 127.0.0.1 too but there was same issue. I was going to get users from users table.


My thought: I changed server name with 127.0.0.1 in core php and it displayed exact same error with laravel.

Can anyone help me? Thanks



via Chebli Mohamed

Remove public from url hosted in sub domain in Laravel

I have hosted my Laravel site in sub domain, its url is something like this:

https://mymaindomain.com/subfolder/public/about-us

Now i want to remove the public from url, my .htaccess file is like:

<IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/beta [L,R=301]
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


via Chebli Mohamed

dimanche 31 mai 2020

laravel validation error and flash session not working

I have installed laravel 5.8 project via :

composer create-project --prefer-dist laravel/laravel project2"5.8.*"

after I run:

php artisan make:auth

I can visit 127.0.0.1:8000/login but when I enter wrong email or password I get redirected back without error messages.

here is my rutes:

 Domain | Method   | URI                    | Name                 | Action                                                                 | Middleware   |
+--------+----------+------------------------+----------------------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      |                      | Closure                                                                | web          |
|        | GET|HEAD | api/user               |                      | Closure                                                                | api,auth:api |
|        | POST     | complete-registration  | completeRegistration | App\Http\Controllers\auth\RegisterController@completeRegistration      | web,guest    |
|        | GET|HEAD | home                   | home                 | App\Http\Controllers\HomeController@index                              | web          |
|        | GET|HEAD | login                  | login                | App\Http\Controllers\Auth\LoginController@showLoginForm                | web          |
|        | POST     | login                  |                      | App\Http\Controllers\Auth\LoginController@login                        | web          |
|        | POST     | logout                 | logout               | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         | password.email       | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         | password.request     | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         | password.update      | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} | password.reset       | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               | register             | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |                      | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
|        | GET|HEAD | verify-code            | verify_code          | App\Http\Controllers\auth\RegisterController@show_verify_code          | web,guest    |

I tried:

php artisan clear:cache
php artisan config:cache
php artisan view:clear
php artisan route:clear

also tried to delete vendor folder and then:

composer install install --no-cache

but nothing worked, why laravel is not returning errors?



via Chebli Mohamed