Laravel Crud Edit

Posted 2 months ago by wuschelino22

Hello, i want to use Edit in CRUD for edit my Datas in the Database i have read the Documentation but i dont understand it. Can Someone help mit to solve my Problem?

here is my Crud Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use View;
use App\Url;
use App\Categorie;


class ShareController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $shares = Url::all();
        $categories = Categorie::all();

        return view('index', compact('shares', 'categories'));


}


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $categories = Categorie::all();
    
        return view('create', compact('categories'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

          $share = new Url([
            'name' => $request->get('name'),
            'urls'=> $request->get('urls'),
            'categorie_id'=> $request->get('categorie_id')
          ]);
          $share->save();
          return back();
    }

    /**
     * Display the specified resource. 
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

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

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

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

    public function search(Request $request)
    {
 

    $urls = Url::where('name', $request->get('search'))
    ->orWhere('name', 'like', '%' . $request->get('search') . '%')->get();

    $shares = $urls;

    $categories = Categorie::whereIn('id', $shares->pluck('categorie_id'))->get();

    return view('index', compact('shares', 'categories'));


    }

    
}

I want the edit Datas in the MYSQL Database wich is called URL hier is my Model File

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Url extends Model
{

    use Softdeletes;

    protected $fillable = [
    
        'name',
        'urls',
        'categorie_id'
    ];

    public function categorieName()
    {
        return $this->belongsTo('App\Categorie', 'categorie_id');
    }
    
}

Thank you so much

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