public function destroy($id)
    {
        $record = $this->modelRepository->findOrFail($id);

        if ( ! $this->isModelDeletable($record)) {
            return $this->failureResponse(
                $this->getLastUnmetDeleteConditionMessage()
            );
        }

        event( new Events\DeletingModelInCms($record) );

        if ( ! $this->deleteModel($record)) {
            // @codeCoverageIgnoreStart
            return $this->failureResponse(
                cms_trans('models.delete.failure.unknown')
            );
            // @codeCoverageIgnoreEnd
        }

        event( new Events\ModelDeletedInCms($this->getModelInformation()->modelClass(), $id) );

        if (request()->ajax()) {
            return response()->json([
                'success' => true,
            ]);
        }

        cms_flash(
            cms_trans(
                'models.delete.success-message',
                [ 'record' => $this->getSimpleRecordReference($id, $record) ]
            ),
            FlashLevel::SUCCESS
        );

        return redirect()->back();
    }
public function destroy($id)
    {
        $record = $this->modelRepository->findOrFail($id);

        if ( ! $this->isModelDeletable($record)) {
            return $this->failureResponse(
                $this->getLastUnmetDeleteConditionMessage()
            );
        }

        event( new Events\DeletingModelInCms($record) );

        if ( ! $this->deleteModel($record)) {
            // @codeCoverageIgnoreStart
            return $this->failureResponse(
                cms_trans('models.delete.failure.unknown')
            );
            // @codeCoverageIgnoreEnd
        }

        event( new Events\ModelDeletedInCms($this->getModelInformation()->modelClass(), $id) );

        if (request()->ajax()) {
            return response()->json([
                'success' => true,
            ]);
        }

        cms_flash(
            cms_trans(
                'models.delete.success-message',
                [ 'record' => $this->getSimpleRecordReference($id, $record) ]
            ),
            FlashLevel::SUCCESS
        );

        return redirect()->back();
    }
public function destroy ( $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; if ( ! $ this -> isModelDeletable ( $ record ) ) { return $ this -> failureResponse ( $ this -> getLastUnmetDeleteConditionMessage ( ) ) ; } event ( new Events \ DeletingModelInCms ( $ record ) ) ; if ( ! $ this -> deleteModel ( $ record ) ) { // @codeCoverageIgnoreStart return $ this -> failureResponse ( cms_trans ( 'models.delete.failure.unknown' ) ) ; // @codeCoverageIgnoreEnd } event ( new Events \ ModelDeletedInCms ( $ this -> getModelInformation ( ) -> modelClass ( ) , $ id ) ) ; if ( request ( ) -> ajax ( ) ) { return response ( ) -> json ( [ 'success' => true , ] ) ; } cms_flash ( cms_trans ( 'models.delete.success-message' , [ 'record' => $ this -> getSimpleRecordReference ( $ id , $ record ) ] ) , FlashLevel :: SUCCESS ) ; return redirect ( ) -> back ( ) ; }
Deletes a record, if allowed.

@param mixed $id
@return mixed
@event DeletingModelInCms
@event ModelDeletedInCms
Deletes a record if allowed .