app/Http/Controllers/EnterpriseThanksAppController.php
/**
	 *
	 * Add new enterprise thanks to the database.
	 *
	 * @param Request $request
	 *
	 * @return Response
	 * 
	 */
Add new enterprise thanks to the database.
@param Request $request

@return Response
Add new enterprise thanks to the database . @param Request $request @return Response
public function store(EnterpriseThanksRequest $request)
    {
        $date = new \DateTime();        
        $enterpriseThanks = new EnterpriseThanks();
        $enterpriseThanks->user_id = Auth::user()->id;
    	$enterpriseThanks->enterprise_id = $request->enterprise_id;
        $enterpriseThanks->thanksDateTime = $date->format('Y-m-d H:i:s');
        $enterpriseThanks->content = $request->contentEnterprise;
        $enterprise = new EnterpriseAdminController();
        $status = $enterprise->verifyStatus($request->enterprise_id);
        if($status == 'Pending') {
            $enterpriseThanks->status = 'Pending';
        } else {
            $enterpriseThanks->status = 'Approved';
        }
    	if($enterpriseThanks->save()) {
            $enterpriseThanks->hash = preg_replace('/[^A-Za-z0-9\-]/', '', bcrypt($enterpriseThanks->id));
            $enterpriseThanks->save();
            $user = new UserAdminController();            
            Mail::to($enterprise->show($request->enterprise_id)->email)->send(new EnterpriseThanksMail($user->show(Auth::user()->id), $enterpriseThanks));
    	    $data = array(
                'enterpriseThanks' => EnterpriseThanks::where('hash', '=', $enterpriseThanks->hash)->with('enterprise')->get(),
                'showMessage' => 'new'
            );
            return view('app.enterprise-thanks.show')->with('data', $data);
        }    
    }
public function store ( EnterpriseThanksRequest $ request ) { $ date = new \ DateTime ( ) ; $ enterpriseThanks = new EnterpriseThanks ( ) ; $ enterpriseThanks -> user_id = Auth :: user ( ) -> id ; $ enterpriseThanks -> enterprise_id = $ request -> enterprise_id ; $ enterpriseThanks -> thanksDateTime = $ date -> format ( 'Y-m-d H:i:s' ) ; $ enterpriseThanks -> content = $ request -> contentEnterprise ; $ enterprise = new EnterpriseAdminController ( ) ; $ status = $ enterprise -> verifyStatus ( $ request -> enterprise_id ) ; if ( $ status == 'Pending' ) { $ enterpriseThanks -> status = 'Pending' ; } else { $ enterpriseThanks -> status = 'Approved' ; } if ( $ enterpriseThanks -> save ( ) ) { $ enterpriseThanks -> hash = preg_replace ( '/[^A-Za-z0-9\-]/' , '' , bcrypt ( $ enterpriseThanks -> id ) ) ; $ enterpriseThanks -> save ( ) ; $ user = new UserAdminController ( ) ; Mail :: to ( $ enterprise -> show ( $ request -> enterprise_id ) -> email ) -> send ( new EnterpriseThanksMail ( $ user -> show ( Auth :: user ( ) -> id ) , $ enterpriseThanks ) ) ; $ data = array ( 'enterpriseThanks' => EnterpriseThanks :: where ( 'hash' , '=' , $ enterpriseThanks -> hash ) -> with ( 'enterprise' ) -> get ( ) , 'showMessage' => 'new' ) ; return view ( 'app.enterprise-thanks.show' ) -> with ( 'data' , $ data ) ; } }
Add new enterprise thanks to the database.
Add new enterprise thanks to the database .