mehmetanbaki

mehmetanbaki

Full Stack Developer at Iraq, Baghdad

Member Since 7 Months Ago

Toronto

Experience Points
50,530
Total
Experience

4,470 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
403
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 11
50,530 XP
Jun
12
3 weeks ago
Activity icon

Started a new Conversation Hayder Hamza

i'm send user info inside token what's a problem in this

May
15
1 month ago
Activity icon

Started a new Conversation JWT AuthController

<?php

namespace App\Http\Controllers;

use JWTAuth;
use App\Core\Helpers\Utilities;
use App\Http\Controllers\Controller;
use App\Core\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:api', ['except' => ['login']]);
    }

    /**
     * Get a JWT token via given credentials.
     *
     * @param  \Illuminate\Http\Request  $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function login(Request $request)
    {
        $credentials = $request->only('phone', 'password');

        if ($token = JWTAuth::attempt( $credentials) ) {
            return $this->respondWithToken($token);
        }
        return Utilities::wrapStatus(['error' => 'Unauthorized'], 401);
    }

    /**
     * Log the user out (Invalidate the token)
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function logout()
    {
        $this->guard()->logout();

        return Utilities::wrap(['message' => 'Successfully logged out']);
    }

    /**
     * Get the token array structure.
     *
     * @param  string $token
     *
     * @return \Illuminate\Http\JsonResponse
     */
    protected function respondWithToken($token)
    {
        return Utilities::wrap([
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => $this->guard()->factory()->getTTL() * 60
        ]);
    }

    /**
     * Get the guard to be used during authentication.
     *
     * @return \Illuminate\Contracts\Auth\Guard
     */
    public function guard()
    {
        return Auth::guard();
    }
}

this is my authcontroller above I have error with it's keep giving me unauthorized and I don't know why

May
14
1 month ago
Activity icon

Started a new Conversation OTP

I have this code but it won't create otp

    public function sendOtp(){

        $codeCache = Cache::get('key');
        if($codeCache != $code){
           return "Please Enter The Correct Code " . $type;
        }
        $credentials;
       $user = User::where('phone', '=', $credentials)->first();
       if (!$user) {
           return response()->json(['error' => 'Please enter the correct code'], 401);
       }

       if (! $token = JWTAuth::fromUser($user)) {
           return response()->json(['error' => 'Unauthorized'], 401);
       }
       $user->details = "";
       $user->save();
       return $this->respondWithToken($token);

    }

    public function otp(Request $request)
    {

        $rand = rand(100000,999999) . rand(100000,999999);
        $second = now()->addMinutes(1);
        $code = rand();
        $value = Cache::put("key",$rand, $second);
        $phone = $request->phone;
        $cell = 964 . substr($phone,1);

        $user->details = $rand;
        $user->save();
        $client = new Client();
        return $response = $client->post('http://sms-gw.net:81/v2/api/Gateway/SendMessage' , [
            'headers' => [
                'Authorization' => 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjE2ZGMwNmEyLThkYWQtNDcyYy1hNDBhLWY3YmQwYWVhZDAxNyIsImVtYWlsIjoiZW5qYXpAc21zLWd3Lm5ldCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJFTkpBWiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkN1c3RvbWVyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwOS8wOS9pZGVudGl0eS9jbGFpbXMvYWN0b3IiOiIyIiwianRpIjoiODQ0MzM3NzAtM2VlMS00NjY3LTg4ODktMDBjOWZhNDdmNDRkIiwibmJmIjoxNTc2NTk0OTAwLCJleHAiOjE2MDgyMTczMDAsImlzcyI6Iklzc3VlciIsImF1ZCI6IkF1ZGllbmNlIn0.xh9avMxWnwHH-uh1QPjLij5CWW5p5fF3ENz4A0xjHb4',
                'Content-Type' => 'application/json'
            ],
            'json' => [
            'number' => $mobile,
            'text' => 'Insert This Code ' . $rand . ' I think this otp is done 0_*',
            'messageType' => 3,
            'sentThrough' => 1
            ]
        ]);
        return response()->json(['success'=>$user->phone], 200);

    }

May
12
1 month ago
Activity icon

Started a new Conversation JWT And OTP

I need to use JWT with OTP is there any package for this or should I create by my own ??

Activity icon

Replied to Middleware

@michaloravec

I use it and working with it a lot but this time I want to create my own package I want to add otp with it and make it customize

Activity icon

Replied to Middleware

@michaloravec

which means I can do it

Activity icon

Started a new Conversation Middleware

Can I build multi-auth with single middleware and using conditions to specific every single role in it ??

And to be specific I want to make one middleware call it authmiddleware and in that middleware I'll put all the roles for authentication is there any problem with that ???

May
06
2 months ago
Activity icon

Started a new Conversation JWT Bugs

I have this code in AuthController;

<?php

namespace App\Http\Controllers;

use JWTAuth;
use App\Core\Models\User;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;

class AuthController extends Controller
{
    public $loginAfterSignUp = true;

    public function login(Request $request)
    {
        $credentials = $request->only("phone", "password");
        $token = null;

        if (!$token = JWTAuth::attempt($credentials)) {
            return response()->json([
                "status" => false,
                "message" => "Unauthorized"
            ]);
        }

        return response()->json([
            "status" => true,
            "token" => $token
        ]);
    }

    public function register(Request $request)
    {
        $this->validate($request, [
            "name" => "required|string",
            "phone" => "required|unique:user",
            "password" => "required|min:6|max:10"
        ]);

        $user = new User();
        $user->name = $request->name;
        $user->phone = $request->phone;
        $user->password = bcrypt($request->password);
        $user->save();

        if ($this->loginAfterSignUp) {
            return $this->login($request);
        }

        return response()->json([
            "status" => true,
            "user" => $user
        ]);
    }

    public function logout(Request $request)
    {
        $this->validate($request, [
            "token" => "required"
        ]);

        try {
            JWTAuth::invalidate($request->token);

            return response()->json([
                "status" => true,
                "message" => "User logged out successfully"
            ]);
        } catch (JWTException $exception) {
            return response()->json([
                "status" => false,
                "message" => "Ops, the user can not be logged out"
            ]);
        }
    }
}


it keep giving me this error:

{
    "status": false,
    "message": "Unauthorized"
}

May
03
2 months ago
Activity icon

Replied to JWT

@xinecraft

I don't wanna save in the database

May
02
2 months ago
Activity icon

Started a new Conversation JWT

Hey Laravelers

I need to create JWT to my application web in Laravel 7 how is that

Apr
29
2 months ago
Activity icon

Started a new Conversation Input Sanitization

how to sanitize user input ($request data), to prevent xss attack??

Apr
22
2 months ago
Activity icon

Started a new Conversation Sanctum API Secret

Hey Laravelers

How can I create secret api token with sanctum ???

Activity icon

Started a new Conversation Token API

Hey Laravelers

Is there any way to create user token api without using passport ???

Apr
02
3 months ago
Activity icon

Started a new Conversation How To To Return User Info With His Resized Image

each user has its images lets say each image 2000X1000 and i want to return user info(name,email, etc..) with resized image200X200 for each user, ihave only the image path saved in database, how to do it using intervation library?

Mar
31
3 months ago
Activity icon

Started a new Conversation Laravel 7 Created_at Returned Value Format

after upgrading to laravel 7 created_at format returned just like this '2020-03-31T09:40:53.000000Z' i just want the old format

Mar
28
3 months ago
Activity icon

Started a new Conversation How To Get Comments And Ratings Of Post In One Api Route

i have three tables posts, ratings and comments just want to get all the comments and ratings of first post in single API route

Mar
14
3 months ago
Activity icon

Replied to Laravel Sum

@sinnbeck

I did it but is the same .

Activity icon

Started a new Conversation Laravel Sum

Hey Laravelers

I have this function :

public function index () {
$items=Item::with('currency', 'origin', 'category', 'itemFiles', 'itemRatings' )->sum('item_price)->get();
return $items
}

it giving me this error:

Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rate' in 'field list' (SQL: select sum(`rate`) as aggregate from `items`) in file C:\xampp\htdocs\in-iraq-laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 669

Mar
01
4 months ago
Activity icon

Started a new Conversation RFID API

Hey Laraverlers

I have an RFID Reader for Garage gate tages but the software doesn't have api to connect it with my laravel app so is there any library or something to do that ???

Thanks a lot early

Feb
22
4 months ago
Activity icon

Replied to Different Table Auth

@jlrdw

I do this just the problem I integrate them with stripe payment method so I want to throwing the admin and the sub-admin away from the payment I thought it'll be better if I make another table to give it only to the payment members

Activity icon

Started a new Conversation Different Table Auth

Hay Laravelers

Can I use another table besides the users table and give it middleware too such as members table to make them go to another dashboard is that possible ??

Feb
21
4 months ago
Activity icon

Started a new Conversation JWT Laravel 6

Hey Laravelers

I want to add token bearer to my users by using middleware as you know the migrations gave me empty token so how can I do it please ??

Feb
18
4 months ago
Activity icon

Started a new Conversation Pin Authentication

Hey Laravelers

I want to make login with mobile phone number without password and after entering the phone the second step will be sending pin code to phone number to login after that will route the login to the role that I gave it to that number such as admin or user. I try to do that with passport but it didn't working???

any one can help me out with that ???

Feb
15
4 months ago
Activity icon

Replied to Version Bugs

@a4ashraf

It giving me that error

Activity icon

Replied to Version Bugs

@a4ashraf

the import model and controller i'ts above with the question and the is the eloquent model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class People extends Model
{
    public $table = 'people';
}
Activity icon

Replied to Version Bugs

@a4ashraf

I import them from excel sheet using laravel-excel package as you can see I try to create fields dynamically as it is with excel sheet how could I input name of the table and name of the fields if it's dynamic

Activity icon

Replied to Version Bugs

@a4ashraf what do you mean of translation and I'm use it but this error show :

ErrorException
Undefined variable: table_name 
Activity icon

Started a new Conversation Version Bugs

Hey Laravelers I have this issue

Symfony\Component\Debug\Exception\FatalThrowableError
syntax error, unexpected ';', expecting ']' 

this is the code:

<?php

namespace App\Http\Controllers;

use App\People;
use DB;
use Illuminate\Http\Request;
use App\Exports\PeopleExport;
use App\Imports\PeopleImport;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;


class PeopleController extends Controller
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function view()
    {
        $tables = DB::select('SHOW TABLES');
        return view('view', [ 'tables' => $tables ]);
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function export()
    {
        return Excel::download(new PeopleExport, 'people.xlsx');
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function import()
    {
        $data = Excel::import(new PeopleImport,request()->file('file'));
        foreach($data->toArray() as $row) {
            $value[] = $row;
            foreach($row as $key => $val) {
                $fields[] = $key;
            }
        }
    $ff = array_unique($fields);

        return back()->withStatus(['تم الرفع']);
    }
}

this is the model

<?php

namespace App\Imports;

use DB;
use App\People;
use Maatwebsite\Excel\Concerns\ToModel;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

class PeopleImport implements ToModel
{
    // importing excel sheet or creating new schema

    public function model(array $row)
    {
        return new People([
            if (!Schema::hasTable($table_name))
            {
                Schema::connection('mysql')->create($table_name, function (Blueprint $table) use ($ff, $table_name) {
                    if (count($ff) > 0) {
                        foreach ($ff as $field) {
                            $table->longText($field)->nullable();
                            $array[] = $field;
                        }
                    }
                });
            }
        ]);
    }
}


Feb
11
4 months ago
Activity icon

Started a new Conversation Integrating Api From Another App

Hey larverlers

I want to integrating api from another application with my laravel application how can I do that ???

Feb
10
4 months ago
Activity icon

Started a new Conversation Mailhog

Hey Laravelers

I'm running the mailhog on my localhost and I'm running this command:

localhost:8025

but it's not working and by the way I'm taking it all from laravel official documentations

Feb
08
5 months ago
Activity icon

Replied to Reading Documentations

@jlrdw

laravel-excel

I understand how to work but couldn't make it on a real application. didn't understand why

Feb
07
5 months ago
Activity icon

Started a new Conversation Reading Documentations

Hey Everyone

I have problem with reading documentations for some packages of plugins I couldn't understand anything of them and it's so confusing because there is no videos about them the make it clear.

how can I deal with that problem

Activity icon

Replied to Controller

@fylzero it's work but why didn't accept id and name

Activity icon

Replied to Controller

@fylzero

As you can see I'm using it just when I changed the store, update and destroy functions it's gave me that error

Activity icon

Replied to Controller

@rymercyble

this appears to me with index blade

Activity icon

Started a new Conversation Controller

Hey Laravelers

I have this issue

Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id`, `name`, `bookings_users`.`booking_id` as `pivot_booking_id`, `bookings_users`.`user_id` as `pivot_user_id`, `bookings_users`.`created_at` as `pivot_created_at`, `bookings_users`.`updated_at` as `pivot_updated_at` from `users` inner join `bookings_users` on `users`.`id` = `bookings_users`.`user_id` where `bookings_users`.`booking_id` in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) 

this is the controller

<?php

namespace App\Http\Controllers;

use App\Booking;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BookingController extends Controller
{

    public function index()
    {
        $bookings = Booking::with(['room.roomType', 'users:id,name'])->paginate(10);
        return view('bookings.index')
            ->with('bookings', $bookings);
    }


    public function create()
    {
        $users = DB::table('users')->get()->pluck('name', 'id')->prepend('none');
        $rooms = DB::table('rooms')->get()->pluck('number', 'id');
        return view('bookings.create')
            ->with('users', $users)
            ->with('booking', (new Booking()))
            ->with('rooms', $rooms);
    }


    public function store(Request $request)
    {
        $booking = Booking::create($request->input());
        $booking->users->attach($request->input('user_id'));

        return redirect()->action('[email protected]');
    }


    public function show(Booking $booking)
    {
        return view('bookings.show', ['booking' => $booking]);
    }


    public function edit(Booking $booking)
    {
        $users = DB::table('users')->get()->pluck('name', 'id')->prepend('none');
        $rooms = DB::table('rooms')->get()->pluck('number', 'id');
        $bookingsUser = DB::table('bookings_users')->where('booking_id', $booking->id)->first();
        return view('bookings.edit')
            ->with('bookingsUser', $bookingsUser)
            ->with('users', $users)
            ->with('rooms', $rooms)
            ->with('booking', $booking);
    }


    public function update(Request $request, Booking $booking)
    {
        $booking->fill($request->input());
        $booking->save();
        $booking->users()->sync([$request->input('user_id')]);
        return redirect()->action('[email protected]');
    }


    public function destroy(Booking $booking)
    {
        $booking->users()->detach();
        $booking->delete();
        return redirect()->action('[email protected]');
    }
}


Feb
06
5 months ago
Activity icon

Started a new Conversation Creating Dynamic Table

Hey Laravelers

Can I create table dynamically from the front view without get back to the models or controllers

Feb
04
5 months ago
Activity icon

Started a new Conversation Response Error

Hey laravelers

I have this controlls


<?php

namespace App\Http\Controllers;
use App\Http\Resources\Material\MaterialResource;
use App\Http\Requests\MaterialRequest;
use App\Model\Material;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class MaterialController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        return MaterialResource::collection(Material::all());
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(MaterialRequest $request)
    {
        //
        $material = new Material;
        $material->name = $request->name;
        $material->code = $request->code;
        $material->quantity = $request->quantity;
        $material->price = $request->price;
        $material->madein = $request->madein;
        $material->dateadd = $request->dateadd;
        $material->extraInfo = $request->extraInfo;
        $material->save();
        return response([
            'data' => new MaterialResource($material)
        ],Response::HTTP_CREATED);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Model\Material  $material
     * @return \Illuminate\Http\Response
     */
    public function show(Material $material)
    {
        //
         //return $material;
         return new MaterialResource($material);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Model\Material  $material
     * @return \Illuminate\Http\Response
     */
    public function edit(Material $material)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Model\Material  $material
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Material $material)
    {
        $out = ($request->quantity + $material->quantity);//add some
    
        $request->quantity=$out;
        return $out;

        $material->update($request->get());
        return response([
        'data' => new MaterialResource($material)
        ],Response::HTTP_CREATED); 

     
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Model\Material  $material
     * @return \Illuminate\Http\Response
     */
    public function destroy(Material $material)
    {
        //
        $material->delete();
        return 'item deleted';
    }
}


didn't give me the total in database table

Activity icon

Started a new Conversation SQL

Hey Laravelers

Can I use this query:

select * from * 

which means

select all tables from all databases

and if it's possible how could I do it

Feb
03
5 months ago
Activity icon

Started a new Conversation Public Function

Hey Laravelers

how could I put public function inside if statement, take a look: is that right ??

<?php

namespace App\Http\Controllers;

use App\People;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use App\Exports\PeopleExport;
use App\Imports\PeopleImport;
use Maatwebsite\Excel\Facades\Excel;

class PeopleController extends Controller
{

    public function index()
    {
        $people = People::all();

        return view('people')->with('people', $people);
    }

    public function import(Request $request)
    {
        if ($request->file('imported_file'))
        {
            Excel::import(new PeopleImport(), request()->file('imported_file'));
            if (!isset('imported_file'))
            {
                public function createTable($table_name, $fields = [])
                {
                    if (!Schema::hasTable($table_name)) {
                        Schema::create($table_name, function (Blueprint $table) use ($fields, $table_name) {
                            $table->increments('id');
                            if (count($fields) > 0) {
                                foreach ($fields as $field) {
                                    $table->{$field['type']}($field['name']);
                                }
                            }
                            $table->timestamps();
                        });
                    }
                }
            }
            return back();
        }
    }

    public function export()
    {
        return Excel::download(new PeopleExport(), 'people.xlsx');
    }

}

Activity icon

Replied to Big Error Import

@ahmeddabak

I'm trying to do this importing file first compared it with the data the contains in my model and after that adding the new data to my table if it's not exist that first step

second step creating table if it's not exist as you can see here

        public function createTable($table_name, $fields = [])
        {
            if (!Schema::hasTable($table_name)) {
                Schema::create($table_name, function (Blueprint $table) use ($fields, $table_name) {
                    $table->increments('id');
                    if (count($fields) > 0) {
                        foreach ($fields as $field) {
                            $table->{$field['type']}($field['name']);
                        }
                    }
                    $table->timestamps();
                });
            }
        }

this to create a table if it's not exist

Activity icon

Replied to Big Error Import

@ahmeddabak Ok that if I know what I'm importing but I'm importing random file and I don't know what's in it, So how could I do that ??

Activity icon

Started a new Conversation Big Error Import

Hey Laravelers:

this is my code and I don't know how to fix it:

I try to create a table in the database when I import it I'm using laravel-excel

this is import-model:


<?php

namespace App\Imports;

use App\People;
use Maatwebsite\Excel\Row;
use Maatwebsite\Excel\Concerns\OnEachRow;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;


class PeopleIMport implements OnEachRow
{

        public function onRow(Row $row)
        {
            People::firstOrCreate($row->toArray());
        }
        public function createTable($table_name, $fields = [])
        {
            if (!Schema::hasTable($table_name)) {
                Schema::create($table_name, function (Blueprint $table) use ($fields, $table_name) {
                    $table->increments('id');
                    if (count($fields) > 0) {
                        foreach ($fields as $field) {
                            $table->{$field['type']}($field['name']);
                        }
                    }
                    $table->timestamps();
                });
            }
        }

}


this is the controller:


<?php

namespace App\Http\Controllers;

use App\People;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use App\Exports\PeopleExport;
use App\Imports\PeopleImport;
use Maatwebsite\Excel\Facades\Excel;

class PeopleController extends Controller
{

    public function index()
    {
        $people = People::all();

        return view('people')->with('people', $people);
    }


    public function import(Request $request)
    {
        if ($request->file('imported_file')) {
            Excel::import(new PeopleImport(), request()->file('imported_file'));
            return back();
        }
    }

    public function export()
    {
        return Excel::download(new PeopleExport(), 'people.xlsx');
    }

}


this is the error:


Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `people` where (`0` = semester and `1` = Industry and `2` = Data Base Name and `3` = Data Source and `4` = Data Base Description and `5` = Database Url and `6` = Data Dictionary Yes or No or Something? and `7` = Number of Rows and `8` = Number of Continous Variables and `9` = Number of Categorical Variables and `10` = Report (1) or Raw Data? (10) 1-10 scale and `11` = Comments) limit 1)
http://localhost:8000/people/import
Hide solutions
A column was not found

You might have forgotten to run your migrations. You can run your migrations using php artisan migrate.

Pressing the button below will try to run your migrations.
Read more

Run migrations

    Database: Running Migrations docs

what I'm trying to do importing randomly excel sheet

Activity icon

Replied to Table View

@tisuchi Ok, but how can view it how can it know it I mean columns it should be dynamically all columns for head and body

Activity icon

Replied to Table View

@tisuchi this is just explain how to get it in the model and controller I want it in the blade page as you can see in the question

Activity icon

Replied to Table View

@tisuchi I want to put something get all the heads for all the columns and put something in the body put all the body columns without write every row code

Activity icon

Started a new Conversation Table View

Hey Laravelers

Can I do code like bring the data from table and view it with foreach loop without getting anything static which means this :

@foreach($users as $user)

    <table>
        <th>{{ head }}</th>
        <td>{{ body }}</td>
    </table>

@endforeach

` ` ` 

what I mean it is getting all the data even if doesn't mention them or it will get what I have with the table ???
Activity icon

Replied to OnEachRow

@sinnbeck Which means it has two different tables and two different indexes one for users and one for groups right???