Jump to content

Archived

This topic is now archived and is closed to further replies.

webdevdea

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 )

Share this post


Link to post
Share on other sites

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'));
}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

[EDIT] Zane beats me

 

seems that you are missing a closing braket for the try... just before the catch

.....
....
} catch..... 
...
...

Share this post


Link to post
Share on other sites

×
×
  • 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.