Jump to content

laravel syntax error, unexpected 'catch' (T_CATCH)


Recommended Posts

I am new to the Laravel Framework, doing an internship and at the very end.. I need some assistance please with some try catch error, Its supposed to throw an error if the site name is already in the database.. If someone could help me please and thank you ..

 

```

  public function create()
         {
                return View::make('edit.create');
         }
         
         public function edit( $clientsite )
        
         {
                return View::make('edit.edit', compact('clientsite'));
         }
         public function saveCreate()
         {
                $input = Input::all();
                
        try
            {
                
                $clientsite = new ClientSite;
                $clientsite->siteName = $input['siteName'];
                $clientsite->description = $input['description'];
                $clientsite->launchDate = $input['launchDate'];
                $clientsite->save();
             
                
                //ClientSite::whereSiteName($clientsite->siteName)->first();
                ClientSite::where('siteName', $clientsite->siteName)->first();
                $clientID = $clientsite['clientID'];//getting clientID for use in join query
                            //queries for retrieving features of each group for the selected client
                $clientFeatures = DB::table('features')->join('clientFeatures', function($join) use($clientID)
{
                $join->on( 'clientFeatures.featureID', '=', 'features.featureID')
                ->where('clientFeatures.clientID', '=', $clientID);
                })->get();
                $groupIDs = array();
                foreach ($clientFeatures as $c) {
                $groupIDs[] = $c->groupID;
                
}

            catch(\Illuminate\Database\QueryException $e)
{
                return View::make('profiles.clientProfiles')->with('clientsite',$clientsite)
                ->with('groupIDs',$groupIDs)
                ->with('clientFeatures',$clientFeatures)
                ->with('status','<strong>'.$siteName.' Site already exist!</strong>');

                ;  
                
         
            }

```

https://github.com/webdevdea/MyDyn ( i have not pushed these changes because I have an error )


public function saveCreate()
{
$input = Input::all();

try
{

$clientsite = new ClientSite;
$clientsite->siteName = $input['siteName'];
$clientsite->description = $input['description'];
$clientsite->launchDate = $input['launchDate'];
$clientsite->save();


//ClientSite::whereSiteName($clientsite->siteName)->first();
ClientSite::where('siteName', $clientsite->siteName)->first();
$clientID = $clientsite['clientID'];//getting clientID for use in join query
//queries for retrieving features of each group for the selected client
$clientFeatures = DB::table('features')->join('clientFeatures', function($join) use($clientID)
{
$join->on( 'clientFeatures.featureID', '=', 'features.featureID')
->where('clientFeatures.clientID', '=', $clientID);
})->get();
$groupIDs = array();
foreach ($clientFeatures as $c)
$groupIDs[] = $c->groupID;

}

catch(\Illuminate\Database\QueryException $e)
{
return View::make('profiles.clientProfiles')->with('clientsite',$clientsite)
->with('groupIDs',$groupIDs)
->with('clientFeatures',$clientFeatures)
->with('status','<strong>'.$siteName.' Site already exist!</strong>');

;

}
}
public function show($clientID)
{
$clientsite = Clientsite::find($clientID);
return View::make('clientsite', compact('clientsite'));
}

You're missing a closing brace

                $clientFeatures = DB::table('features')->join('clientFeatures', function($join) use($clientID)
{
                $join->on( 'clientFeatures.featureID', '=', 'features.featureID')
                ->where('clientFeatures.clientID', '=', $clientID);
                })->get();
                $groupIDs = array();
                foreach ($clientFeatures as $c) {
                $groupIDs[] = $c->groupID;
                
}
} catch
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.