Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.0 kB
0
Indexable
Never
// controller
public function store(Request $request)
    {
        
        $request->validate([
            'pages_category_id' => 'required',
            'name' => 'required',
            'content' => 'required',
            'thumbnail' => 'required|image',
        ]);

        $input = $request->all();

        if ($image = $request->file('image')) {
            $destinationPath = 'uploads/pages/';
            $profileImage = date('Ymd.His') . "." . $image->getClientOriginalExtension();
            $image->move($destinationPath, $profileImage);
            $input['image'] = "$profileImage";
        }

        Pages::create($input);

        return redirect('pages/list')->with('success', 'Success Add Page');



//Create
<div class="card">
    <div class="card-body">
        <a href="/pages/list" class="btn btn-success mb-3"> Back To Pages</a>
        <div class="row">
            <div class="col-12">
                <form action="{{ route('create-pages') }}" method="POST" enctype="multipart/form-data">
                    {{ csrf_field() }}
                    {{-- <div class="form-group">
                        <label>Page Category</label>
                        
                        {!! Form::select('page_category', $pagesCategories, old('page_category'), ['class' => 'form-control', 'placeholder' => 'Choose One', 'required']) !!} --}}
                    
                        <div class="form-group">
                            <label>Page Category</label>
                            <select name="pages_category_id" class="form-control select2" style="width: 100%;" required>
                                <option selected="selected">Choose One</option>
                                @foreach ($pagesCategory as $pag)
                                    <option value="{{ $pag->id }}"> {{ $pag->name }} </option>
                                @endforeach
                            </select>
                    </div>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" name="name" id="name" class="form-control" placeholder="Name" required>
                    </div>
                    <div class="form-group">
                        <label>Content</label>
                        <textarea name="content" id="content" cols="30" rows="15"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="formFile" class="form-label">Thumbnail</label>
                        <input class="form-control-file" type="file" name="thumbnail" id="thumbnail">
                    </div>
                    
                    <button type="submit" class="btn btn-success"><span class="fa fa-save"></span> Save</button>
                </form>
            </div>
        </div>
    </div>
</div>






Leave a Comment