src/Http/Controllers/UrlController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Gallib\ShortUrl\Http\Requests\UrlRequest  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(UrlRequest $request, $id)
    {
        $url = Url::findOrFail($id);
        \Cache::forget("url.{$url['code']}");
        $data = [
            'url' => $request->get('url'),
            'code' => $request->get('code'),
            'user_id' => optional(auth()->user())->id,
        ];
        if ($request->filled('expires_at')) {
            $data['expires_at'] = Carbon::parse($request->get('expires_at'))->toDateTimeString();
        }
        $url->update($data);
        return new UrlResponse($url);
    }
public function update ( UrlRequest $ request , $ id ) { $ url = Url :: findOrFail ( $ id ) ; \ Cache :: forget ( " url. { $ url [ 'code' ] } " ) ; $ data = [ 'url' => $ request -> get ( 'url' ) , 'code' => $ request -> get ( 'code' ) , 'user_id' => optional ( auth ( ) -> user ( ) ) -> id , ] ; if ( $ request -> filled ( 'expires_at' ) ) { $ data [ 'expires_at' ] = Carbon :: parse ( $ request -> get ( 'expires_at' ) ) -> toDateTimeString ( ) ; } $ url -> update ( $ data ) ; return new UrlResponse ( $ url ) ; }
Update the specified resource in storage.
Update the specified resource in storage .