8 months ago

how to get all the data from my database

Posted 8 months ago by Lestah

here's my view add_category.blade.php i just want to get all the category from my categories table and list it on my dropdown list so when the page displays i can select from the drowdown list and add whatever i choose from the list coming from my database table categories

<div class="control-group">
                <label class="control-label">Category Level</label>
                <div class="controls">
                  <select name="parent_id" style="width: 220px;">
                    <option value="0">Main Category</option>
                    @foreach($levels as $val)
                      <option value="{{ $val->id }}">{{ $val->name }}</option>

here's my controller CategoryController

public function addCategory(Request $request)
            $data = $request->all();
            //echo "<pre>"; print_r($data); die;
            $category = new Category;
            $category->name = $data['category_name'];
            $category->parent_id = $data['parent_id'];
            $category->description = $data['description'];
            $category->url = $data['url'];
            return redirect('/admin/view-categories')->with('flash_message_success','Category added Successfully!');

        $levels = Category::where(['parent_id'=>0])->get();

        return view('admin.categories.add_category')->with(compact('levels'));

here's my route

Route::match(['get','post'],'/admin/add-category','[email protected]');

Laravel is not giving me any errors

Please sign in or create an account to participate in this conversation.