lundi 2 mars 2020

Laravel user management in Admin Dashboard

i building a user management page in my dashboard so admin can create and update user information from the dashboard...

but, i have no clue to create update and create method especially when we talk about password because it must be Hashed!!

is there any idea to do this??

User Table

Name - email - password - avatar



via Chebli Mohamed

How can I Insert multi inputs using pivot table in laravel?

I have 3 tables:

  • stations (id,station_name)
  • products (id,product_name)
  • product_station (station_id,product_id)

enter image description here

I already have inserted stations and products and i want to insert multi products to the selected station using Pivot table

ProductStationController

public function edit($id)
    {
        $station = Station::findOrFail($id);

        $products = Product::pluck('product_name','id')->all();

        return view('admin.product_station.edit',compact('station','products'));
    }

enter image description here

and I add this code to insert the multi products to the selected station But it does not work So i need help plz :)

public function update(Request $request, $id) { $station = Station::findOrFail($id);

   $products = explode(",", $request->get('products'));
   $product_ids1 = [];
   $product_ids2 = [];
   $product_ids3 = [];
   $product_ids4 = [];

   foreach ($products as $product) {
     $product_db = Product::where('product_name', trim($product))->Create(['product_name' =>
     trim($product)]);

     $product_ids1[] = $product_db->id;
     $product_ids2[] = $product_db->id;
     $product_ids3[] = $product_db->id;
     $product_ids4[] = $product_db->id;
        }

        $station->products()->syncWithoutDetaching($product_ids1);
        $station->products()->syncWithoutDetaching($product_ids2);
        $station->products()->syncWithoutDetaching($product_ids3);
        $station->products()->syncWithoutDetaching($product_ids4);

        $station->update($request->all());

        return redirect('/admin/stations');
    }


via Chebli Mohamed

PHP: How to convert binary string to normal string in PHP 7.2

How can I convert this binary string:

b"iphonée@3,;= ÑÑñe x"

To normal string?

I really need to have that string as a normal string, and not as a binary string.

I am having problems saving in MySQL this binary string. If the CSV that I decode does not have ñ, é or any of this non usual characters, I dont have problem saving. But when one of this characters is set on a cell, the string appears to be binary string and I get an error when saving on MySQL this binary string.

I get this error:

QueryException {#1780
  #sql: "insert into `seller_product_languages` (`seller_product_id`, `lang`, `name`, `description`, `description_html`, `bullet_html`, `bullet`, `meta_keywords`, `default`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
  #bindings: array:11 [
    0 => 117
    1 => "es"
    2 => b"iphonée@3,;= ÑÑñe x"
    3 => "negro"
    4 => "negro"
    5 => null
    6 => ""
    7 => null
    8 => 1
    9 => "2020-03-02 18:40:56"
    10 => "2020-03-02 18:40:56"
  ]
  #message: b"SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1 (SQL: insert into `seller_product_languages` (`seller_product_id`, `lang`, `name`, `description`, `description_html`, `bullet_html`, `bullet`, `meta_keywords`, `default`, `updated_at`, `created_at`) values (117, es, iphonée@3,;= ÑÑñe x, negro, negro, , , , 1, 2020-03-02 18:40:56, 2020-03-02 18:40:56))"
  #code: "HY000"
  #file: "/home/vagrant/Code/PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
  #line: 664
  -previous: PDOException {#1779
    #message: "SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1"
    #code: "HY000"
    #file: "/home/vagrant/Code/PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
    #line: 458
    +errorInfo: array:3 [
      0 => "HY000"
      1 => 1366
      2 => "Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1"
    ]

Environment: -PHP 7.2 -Laravel 5.5 -Ubuntu 18.04



via Chebli Mohamed

Is it worth it to migrate from laravel 5.0 to laravel 7.0 or better to just rebuild all website? [closed]

I became new junior web developer at the company, senior developer left the company and left all gigantic website in my arms. Code in this laravel project is quite bad and complicated, but a lot of good stuff implemented. I can't decide is it worth it to rebuild everything, or better to try upgrade everything? This project running on laravel 5.0 with php 5. As time is important for me I wonder what do you think guys? Is it worth to invest time to resolve all bugs between packages and so on? It's kind of big distance between laravel 5.0 with php5 on and newest laravel 7 (released today) and php7.

P.S I don't really want to rebuild the site as I am new with SEO stuff, so I am afraid that I can impact quite badly our SEO score after migration to new website.



via Chebli Mohamed

How to seed specific table as part of migration - Laravel 5?

I have this commands

php artisan db:seed --class=GraphsTableSeeder

that I need to run in my part of my code (migration).

How do I do that ?

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

use App\Models\Graph;


class RescueGraphsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('graphs')) {

            $graphRecords = Graph::all();

            if(count($graphRecords) == 42){
                echo "graphs table has good data.";
            }

            //truncate
            DB::table('graphs')->truncate();

            //add data
            //php artisan db:seed --class=GraphsTableSeeder ✨

        } else {

            //add graphs table

            //add data
            //php artisan db:seed --class=GraphsTableSeeder ✨

        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

I'm kind of stuck, please help.



via Chebli Mohamed

what does it mean "(include_path='.:/usr/local/php73/pear')" occur error on server upload my laravel project?

I have uploaded my laravel project on server my server it's given below error:

Fatal error: require_once(): Failed opening required '/home/shubhpra/solwin_testyuvasurat/appservice/public/index.php' (include_path='.:/usr/local/php73/pear') in /home/shubhpra/solwin_testyuvasurat/appservice/index.php on line 21

plz help me



via Chebli Mohamed

Manipulate DOM in sessions user differents

i have a question. For example, i have a buttom in a list. I would that if a user that is log in in the system did click in this bottom if other user log in in the same system and see the same view, he can't click in the same buttom.

This is possible made without DB? what tecnology i could use for made this?



via Chebli Mohamed