Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/app/Modules/Testimonials/Http/Controllers/Admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/app/Modules/Testimonials/Http/Controllers/Admin/TestimonialsController.php
<?php

namespace App\Modules\Testimonials\Http\Controllers\Admin;

use App\Http\Controllers\AdminController;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Modules\Testimonials\Http\Requests\TestimonialRequest;
use App\Modules\Testimonials\Models\Testimonial;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laracasts\Flash\Flash;
use Yajra\Datatables\Datatables;

class TestimonialsController extends AdminController
{

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $this->data['page_title'] = trans('testimonials::testimonials.page_title');
        return view('testimonials::admin.testimonials_index', $this->data);
    }

    /**
     * Show a list of all companies
     *
     * @return mixed
     */
    public function data(Request $request)
    {
    
        //create object contact
        $obj = \DB::table('testimonials');

        //create array with permissions access
        $this->data['can'] = [
            'edit'   => $this->data['user']->roles()->pluck('slug')[0] === 'developer',
            'delete' => $this->data['user']->roles()->pluck('slug')[0] === 'developer',
        ];

        //return datatables data
        return $dataTable = Datatables::of($obj)
            ->editColumn('body', function ($o) {
                return Str::limit($o->body, 100);
            })
            ->editColumn('is_active', function ($o) {
                $active = trans_choice('testimonials::testimonials.text_is_active', $o->is_active);
                return $active;
            })
            ->addColumn('user_name', function ($o) {
                return $o->user->name ?? '-';
            })
            ->addColumn('actions', function ($o) {
                $this->data['o'] = $o;
                return view('testimonials::admin.testimonials_list_actions', $this->data)->render();
            })
            ->rawColumns(['body','actions','is_active'])
            ->removeColumn('id')
            ->removeColumn('updated_at')
            ->make(true);

        dd($dataTable);
    }

    /**
     * Get object entries
     * @param Request $request
     */
    protected function getData(Request $request)
    {
        $obj = Testimonial::query();

        //return object
        return $obj;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        $this->data['page_title'] = trans('testimonials::testimonials.page_title');

        //show page
        return view('testimonials::admin.testimonials_create_edit', $this->data);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store(TestimonialRequest $request)
    {

        $data = [
            'user_name' => $request->user_name,
            'user_email' => $request->user_email,
            'posted_at' => Carbon::createFromFormat('d F Y', $request->posted_at)->format('Y-m-d H:i:s'),
            'body' => $request->body,
            'is_active' => (int)$request->is_active,
        ];

        //save new service type
        $obj = Testimonial::create($data);

        //redirect
        if ($request->save) {
            return redirect(route('admin.testimonials.edit', ['testimonial' => $obj->id]));
        } elseif ($request->save_exit) {
            return redirect(route('admin.testimonials.index'));
        }
    }

    /**
     * Edit Service Type
     *
     * @param $label
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function edit(Testimonial $testimonials)
    {
        $this->data['page_title'] = trans('testimonials::testimonials.page_title');
        $this->data['obj'] = $testimonials;

        //show page
        return view('testimonials::admin.testimonials_create_edit', $this->data);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int $id
     * @return Response
     */
    public function update(TestimonialRequest $request, Testimonial $testimonials)
    {

        //fields to be updated
        $fillable = $testimonials['fillable'];

        $fields = array();
        foreach ($request->all() as $field => $f) {
            if (in_array($field, $fillable)) {
                $fields[$field] = $f;
            }
        } //end foreach

        $fields['is_active'] = (int)$request->is_active;
        $fields['posted_at'] = Carbon::createFromFormat('d F Y', $request->posted_at)->format('Y-m-d H:i:s');


        //update label
        Testimonial::where('id', $testimonials->id)->update($fields);

        //redirect
        if ($request->save) {
            return redirect(route('admin.testimonials.edit', ['testimonial' => $testimonials->id]));
        } elseif ($request->save_exit) {
            return redirect(route('admin.testimonials.index'));
        }
    }

    /**
     * Delete page
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function delete(Testimonial $testimonials)
    {
        $this->data['obj'] = $testimonials;

        return view('testimonials::admin.testimonials_delete', $this->data);
    }

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

        //delete contact
        $testimonials->delete();

        //set success message
        Flash::info(trans('testimonials::testimonials.message_confirm_delete', ['name' => $testimonials->user_name]));

        //redirect to contacts list
        return redirect(route('admin.testimonials.index'));
    }
}

ZeroDay Forums Mini